Oops 2 05
Oops 2 05
Eg:
1) class P:
2) 10 methods
3) class C(P):
4) 5 methods
In the above example Parent class contains 10 methods and these methods automatically
available to the child class and we are not required to rewrite those methods(Code Reusability)
Hence child class contains 15 methods.
Note:
What ever members present in Parent class are by default available to the child class through
inheritance.
Demo Program:
1) class P:
2) def m1(self):
3) print("Parent class method")
4) class C(P):
5) def m2(self):
6) print("Child class method")
7)
8) c=C();
9) c.m1()
10) c.m2()
Output:
Parent class method
Child class method
What ever methods present in Parent class are automatically available to the child class and hence
on the child class reference we can call both parent class methods and child class methods.
1) class P:
2) a=10
3) def __init__(self):
4) self.b=20
5) class C(P):
6) c=30
7) def __init__(self):
8) super().__init__()===>Line-1
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
5 040 – 64 51 27 86, 80 96 96 96 96, 92 46 21 21 43 | www.durgasoft.com