-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.
Heirarchical Inheritance-
- when more than one child class are inherits the property of the same parent class then this type of inheritance are said to be Heirarchical Inheritance.
Syntax-
class A():
body
class B(A):
body
class C(A):
body
class D(A):
body
-Here class A is a parent class, and class B, class C, class D are child class which inherits the property of the class A.
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(A):
def func3(self):
print("Function of C class")
class D(A):
def func4(self):
print("Function of D class")
#create objects
b=B()
b.func1()
b.func2()
c=C()
c.func1()
c.func3()
d=D()
d.func1()
d.func4()
Function of A class
Function of B class
Function of A class
Function of C class
Function of A class
Function of D class