Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d79c98a

Browse files
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)

AltStyle によって変換されたページ (->オリジナル) /