Site icon i2tutorials

Python-Inheritance-quiz

This Quiz contains totally 10 Questions each carry 1 point for you.

1. Which of the class methods you can access, when inheriting from another class?

 
All of them
It depends on the class
None of them
Don’t know

Correct!

Wrong!

2. How do you inherit from another class?
Just pass the name of the other class in as a parameter when you name your new class
By calling it as a module on the first line of your new class
By naming it
Don’t know

Correct!

Wrong!

3. When instantiating your new class, which parameters from the old class do you need to pass?
It depends on the class
Only the ones you intend to use in your new class
Above two options
None of the above

Correct!

Wrong!

4. When a child class inherits from only one parent class, it is called?
Single inheritance
Singular inheritance
Multiple inheritance
Multilevel inheritance

Correct!

Wrong!

5. What will be the output of the following Python code?
class Test:
    def __init__(self):
       self.x = 0
class Derived_Test(Test):
    def __init__(self):
       self.y = 1
def main():
   b = Derived_Test()
    print(b.x,b.y)
main()
0 1
0 0
Error since class B inherits A but variable x isn’t inherited
Error since when object is created, argument must be passed like Derived_Test(1)

Correct!

Wrong!

6. Which of the following statements isn’t true?
Superclass non-private method can be overridden
A derived class is a subset of superclass
we can change the value of a private variable in the superclass in the subclass
The constructor of superclass is invoked automatically, when invoking the constructor from a subclass

Correct!

Wrong!

7. What will be output for the folllowing code?
class Test:
   def __init__(self):
       self.x = 0
class Derived_Test(Test):
   def __init__(self):
       Test.__init__(self)
       self.y = 1
def main():
   b = Derived_Test()
   print(b.x,b.y)
main()
Error, the invoking method’s syntax is wrong
The program executes well but nothing is printed
0 1
1 2

Correct!

Wrong!

8. What is true about Inheritance in Python?

 
Inheritance is the ability of one class to inherit or derive the properties from another class.
It represents real-world relationships well.
It provides reusability of a code.
All of the above

Correct!

Wrong!

9. Which inheritance is a blend of more than one type of inheritance?

 
Single inheritance
Hybrid inheritance
Multiple inheritance
Multilevel inheritance

Correct!

Wrong!

10. Parent class is the class being inherited from, also called?

 
Derived class
Child class
Hybrid class
Base class

Correct!

Wrong!

Share the quiz to show your results !

Subscribe to see your results

Ignore & go to results

Python-Inheritance-quiz

You got %%score%% of %%total%% right

%%description%%

%%description%%

Where to go ?

Quizzes

Loading...

Exit mobile version