Python Classes & Inheritance: Working with Inheritance in Python
Question : Which of the following statements is true about classes and inheritance?
The child class is also called the subclass The parent class is also called the base class
Question : Which of the following way(s) to define the Employee class is correct?
class Employee(): pass class Employee: pass class Employee(object): pass
Consider this bit of code below: class Canine(): def bark(self): print("Medium bark") class Labrador(Canine): def bark(self): print("Loud bark") class Poodle(Canine): def bark(self): print("Soft bark") class Beagle(Canine): pass d = Labrador() What will be the output of d.bark()?
"Loud bark"
Consider this bit of code below: class Canine(): def bark(self): print("Medium bark") class Labrador(Canine): def bark(self): print("Loud bark") class Poodle(Canine): def bark(self): print("Soft bark") class Beagle(Canine): pass d = Canine() What will be the output of d.bark()?
"Medium bark"
Question : Which of the following statements are true about inheritance?
Base classes may provide default method implementations which derived classes override Derived classes can re-implement methods defined in the base class Derived classes can call the __init__() methods of the base class
Question : Which of the following is true about multiple and multilevel inheritance in Python?
Both multiple and multilevel inheritance are supported in Python
Question : What kind of relationship does class inheritance help model?
Is-a
Question : What kind of relationships does multiple inheritance help model?
Multiple is-a relationships
Question : Consider a base class Shape, suppose we have a class named Rectangle which inherits from Shape. For a method get_area() invoked on an object of type Rectangle what will be the order Python will use to resolve or find the right implementation of this method?
Rectangle Shape builtins.object
Question : Which of the following ways are valid for invoking the superclass _init_(self, name) method from a derived class? Assume that the base class is named Employee.
super().__init__(self, name) Employee.__init__(self, name)