multi-level inheritance in python by R4R Team

-Inheritance allows us to define a class that inherits all the methods and properties from another class. Parent class- it is the class being inherited from, also called base class. Child class- Child class is the class that inherits from another class, also called derived class. Syntax- class A():

-Inheritance allows us to define a class that inherits all the methods and properties from another class.

Parent class-
it is the class being inherited from, also called base class.

Child class-
Child class is the class that inherits from another class, also called derived class.

Syntax-

class A():
body
class B(A):
body
class C(B):
body
class D(C):
body


program-

#create class
class A():
def func1(self):
print("Function of A class")

class B(A):
def func2(self):
print("Function of B class")

class C(B):
def func3(self):
print("Function of C class ")

class D(C):
def func4(self):
print("function of D class")

obj=D()

obj.func1()
obj.func2()
obj.func3()
obj.func4()


output-

Function of A class
Function of B class
Function of C class
function of D class


-In this program, we create a four class in which class D is a child class and class A is parent class, class B ad class C are parent as well as child class.
-Here we create an objetc of the class D, which inherits the property of the class , so object of class D i.e. obj=D() are able to call all the methods of every class.




body class B(A): body class C(B): body class D(C): body program-#create class class A(): def func1(self): print("Function of A class") class B(A): def func2(self): print("Function of B class") class C(B): def func3(self): print("Function of C class ") class D(C): def func4(self): print("function of D class") obj=D() obj.func1() obj.func2() obj.func3() obj.func4() output-Function of A class Function of B class Function of C class function of D class -In this program, we create a four class in which class D is a child class and class A is parent class, class B ad class C are parent as well as child class. -Here we create an objetc of the class D, which inherits the property of the class , so object of class D i.e. obj=D() are able to call all the methods of every class.
Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!