Skip to content

Commit ec558e7

Browse files
inheritence examples
1 parent 9a82ee7 commit ec558e7

3 files changed

Lines changed: 29 additions & 17 deletions

File tree

Constructer_inheritence.oy.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Animal:
2+
def __init__(self):
3+
print("constructer of animal class")
4+
5+
class Dog(Animal):
6+
def __init__(self):
7+
print("constructer of dog class")
8+
# d = Animal()
9+
d=Dog() # output will chage according to the class which we are creating object of. if we create object of dog class then constructer of dog class will run and if we create object of animal class then constructer of animal class will run.
10+
#simplly creeating object ni call chesthe constructer of that class run avtundi

invoke_BaseClass.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Animal:
2+
def __init__(self):
3+
print("constructer of animal class")
4+
5+
class Dog(Animal):
6+
def __init__(self):
7+
super().__init__() # Call the constructor of the parent class
8+
print("constructer of dog class")
9+
d = Dog() # output will show both constructors being called. First, the constructor of the Animal class will run, followed by the constructor of the Dog class.
10+
# output anedi manam enni class aithe esthamo ani vasati , simpley ga chepali ante ouput lo constructers vastai .

tempCodeRunnerFile.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
class Employee:
2-
def __init__(self,role,dept,sala):
3-
self.role=role
4-
self.dept=dept
5-
self.sala=sala
6-
def showdetails(self):
7-
print("role",self.role,"department=",self.dept,"salary",self.sala)
8-
class Engineer(Employee):
9-
def __init__(self,name,age):
10-
self.name=name
11-
self.age=age
12-
super().__init__("SDE","Head",150000)
13-
def all(self):
14-
print("name is",self.name,"his age is ", self.age)
15-
self.showdetails()
16-
E=Engineer("Kondareddy",21)
17-
E.all()
1+
class Animal:
2+
def __init__(self):
3+
print("constructer of animal class")
4+
5+
class Dog(Animal):
6+
def __init__(self):
7+
print("constructer of dog class")
8+
# d = Animal()
9+
d=Dog()

0 commit comments

Comments
 (0)