Skip to content

Commit d79c98a

Browse files
committed
Inheritance in python
1 parent fd26349 commit d79c98a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

inheritance_in_python/inheritance.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Parent:
2+
def __init__(self, last_name, eye_color):
3+
print("Parent Constructor Called")
4+
self.last_name = last_name
5+
self.eye_color = eye_color
6+
7+
def show_info(self):
8+
print("Last Name - " + self.last_name)
9+
print("Eye color - " + self.eye_color)
10+
11+
12+
class Child(Parent):
13+
def __init__(self, last_name, eye_color, num_of_toys):
14+
print("Child Constructor Called")
15+
Parent.__init__(self, last_name, eye_color)
16+
self.number_of_toys = num_of_toys
17+
18+
19+
billy_cyrus = Parent("Cyrus", "blue")
20+
# print(billy_cyrus.last_name)
21+
billy_cyrus.show_info()
22+
23+
# miley_cyrus = Child("Cyrus", "Blue", 5)
24+
# print(miley_cyrus.last_name)
25+
# print(miley_cyrus.number_of_toys)

0 commit comments

Comments
 (0)