Inheritance-
-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.
Constructor-
-constructor is a special type of function of the class which is automatically call when the instance of the class is created.
Syntax-
def __init__(self,arg):
body
program-
#create class A
class A():
def __init__(self):
print("Constructor of class A")
#create class B
class B():
def __init__(self):
print("Constructor of class B")
#create class C inherits the class A and class B
class C(A,B):
def __init__(self):
print("Constructor of class C")
#create objects
c=C()
b=B()
a=A()
Constructor of class C
Constructor of class B
Constructor of class A