Q1 – An object is created using __________ .
Q2 – _____ is a python special method used to initialize the values of instance members for the new object.
Q3 – _________ is a used to access the attributes and methods of the class in python.
Q4 – A class can serve as base class for many derived classes.
Practice Session – Inheritance
Q1 – Consider class C in a multiple inheritance hierarchy and inherits from classes B and A, write a statement which returns order in which Python looks for a method in a hierarchy of classes for class C as tuple?
Q2 – Assume you have 3 classes A,B and C, ll in the following code to achieve multilevel inheritance class A: Pass class B(A): Pass
Q3 – Suppose Student class derived from the class Person, write a piece of code to invoke the __init__ method in Person from Student?
Post Quiz – Inheritance
Q1 – Which of the following statements are true about inheritance
Answer: Inheritance represents ISA relationship, Inheritance provides reusability of code, Inheritance provides Easy maintenance
Q2 – More than one derived class are created from a single base class is known as
Answer: Hierarchical inheritance
Q3 – Super() class method is used to
Answer: Invoke immediate parent class constructor, Invoke immediate parent class overridden method
Q4 – In case of multiple inheritance, any particular attribute is searched rst in current class. if not found, it searches into parent class in
Answer: Depth rst, left right fashion
Q5 – _____ ensures a class always appears before its parent and in case of multiple parents, the order is same as tuple of base classes.
Answer: method resolution order
Check Your Understanding – Inheritance
Q1 – Match the following
a child class inherits all the properties of a parent class
a derived class will inherit a base class and as well as the derived class also act as the base class to other class
a child class inherits the properties of more than one parent class
More than one child classes inherit all the properties of the same parent class.
Q2 – Predict the output of following piece of code
class F(A, B):
Q3 – Re-arrange the given code to get output given below:
Output should be like:
print(“Name: “, self.name)
print(“Company: “, self.comp)
print(“Hospital: “, self.hos)
doc = Doctor(1,”Arrif”,”APPOLO”)
Q4 – By Inheritance the members of parent class can be reused by all the subclass
Q5 – Predict the output of the following piece of code
class A(X, Y):
class B(Y, Z):
- Saving Bank Account
- Student Information
- Maintain Project Information
- Classic Curve Members
- Faculties and Students