1.

Observe the following class definition and answer the question that follow:class ParentClass(objects):def__init__(self)self,x = 1self.y = 10def print(self):print(self.x, self.y)class ChildClass(ParentClass):def__init__(self):super(ChildClass, self).init_() # Line 1self,x = 2self.y = 20c = ChildClass()c.print()(a) Explain the relevance of Line1.(b) What type of inheritance is being demonstrated in the above code?

Answer»

(a) super() function is used to call the methods of base class which have been extended in derived class. Also, it is the importance of derived class __init__() to invoke the base class __init__()

(b) Single level Inheritance



Discussion

No Comment Found

Related InterviewSolutions