-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClassInheritence.py
55 lines (40 loc) · 958 Bytes
/
ClassInheritence.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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")
def speak(self):
print("I don't know what I say")
class Cat(Pet):
# def __init__(self, name, age):
# self.name = name
# self.age = age
def __init__(self, name, age, color):
super().__init__(name, age)
self.color = color
def speak(self):
print("Meow")
def show(self):
print(f"I am {self.name} and I am {self.age} years old and I am {self.color}")
class Dog(Pet):
# def __init__(self, name, age):
# self.name = name
# self.age = age
#
def speak(self):
print("Bark")
class Fish(Pet):
pass
p = Pet("Tim", 19)
p.show()
p.speak()
c = Cat("Bill", 34, "Blue")
c.show()
c.speak()
d = Dog("Jill", 25)
d.show()
d.speak()
f = Fish("Bubbles", 10)
f.show()
f.speak()