Multilevel inheritance

In this type of inheritance, a class can inherit from a child class or derived class. Let's take a simple example code classmultilevel.py to understand:

class A():
def sum1(self,a,b):
c = a+b
return c

class B(A):
pass

class C(B):
pass

c_obj = C()
print "Sum is ", c_obj.sum1(12,4)

In the preceding example, you can see that class B inherited from class A and class C inherited from class B. The instance of class C can call the method of class A. Let's see the output:

Output of code classmultilevel.py

The preceding output shows that the code is running successfully.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.70.38