multiple 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.

Multiple Inheritance-
When a child class inherits the property of more then one parent class then it is said to be multiple inheritance.

Syntax-

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

-Here class C is inherits the property of class A and class B.


program-

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

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

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

obj=C()

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


output-

Function of A class
Function of B class
Function of C class


-In this program, we create a class A, class B and class C, where class A and class B are independent from each other, but class C inherits the property of both class A and class B.




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!