0% found this document useful (0 votes)
11 views1 page

Oops 2 05

The document explains the concept of inheritance in object-oriented programming, where a child class automatically inherits methods and variables from a parent class, promoting code reusability. It provides a demo program illustrating how methods from the parent class can be called using a child class instance. Additionally, it highlights that variables defined in the parent class are also accessible in the child class.

Uploaded by

vishnu050621
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Oops 2 05

The document explains the concept of inheritance in object-oriented programming, where a child class automatically inherits methods and variables from a parent class, promoting code reusability. It provides a demo program illustrating how methods from the parent class can be called using a child class instance. Additionally, it highlights that variables defined in the parent class are also accessible in the child class.

Uploaded by

vishnu050621
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Parent instance method

Parent class method


Parent static method

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.

Similarly variables also

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

You might also like