File tree Expand file tree Collapse file tree
codes_in_Aug2025/OOPS/INHERITANCE Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class employee :
2+ company = "works in Microsoft"
3+
4+ def __init__ (self ):
5+ print ("Employee class constructor." )
6+
7+ class coder (employee ): # Inherits from employee
8+ language = "Python"
9+ company = "Works in Google" # Overriding the company attribute
10+ def __init__ (self ):
11+ print ("Coder class constructor." )
12+
13+ def showlanguage (self ):
14+ print (f"The language used is { self .language } ." )
15+
16+ class manager (coder ):
17+ name = "Rani" # Inherits from coder
18+ def __init__ (self ):
19+ print ("Manager class constructor." )
20+ def showname (self ):
21+ print (f"The name of the manager is { self .name } ." )
22+
23+ karan = employee () # This will call the employee constructor
24+ print (karan .company )
25+ #---------------------
26+ rohit = coder ()
27+ print (rohit .company )
28+ rohit .showlanguage ()
29+ #-----------------------
30+ rani = manager ()
31+ print (rani .company )
32+ rani .showlanguage ()
33+ rani .showname () # This will call the showname method of manager
34+
35+ #----------Use of super() to call parent class methods----------
You can’t perform that action at this time.
0 commit comments