-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.py
More file actions
38 lines (30 loc) · 867 Bytes
/
Copy pathinheritance.py
File metadata and controls
38 lines (30 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Pet:
def __init__(self,name,age):
self.name = name
self.age = age
def show(self):
print(f"I am {self.name} and I am {self.age} years old.")
class Dog(Pet):
'''def __init__(self,name,age):
self.name = name
self.age = age''' #do not need this because this is same in both so made a new class
def speak(self):
print('Bark')
class Cat(Pet):
def __init__(self,name,age,color):
super().__init__(name,age)
self.color = color
def show(self):
print(f"I am {self.name} and I am {self.age} years old and My color is {self.color}.")
def speak(self):
print('Meow')
class Fish(Pet):
pass
p = Pet('Timn',19)
p.show()
c = Cat('Bill',13,'black')
c.show()
d = Dog('Jill',88)
d.show()
f = Fish('Bubble',5)
f.show()