-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinheritance.py
44 lines (34 loc) · 903 Bytes
/
inheritance.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
# inheritance
class Animal:
def __init__(self):
self.color = ""
self.eat = ""
def set_color (self,color):
self.color = color
def set_eat (self,eat):
self.eat = eat
class Dog(Animal):
def __init__(self):
self.name = ""
self.sound = ""
def set_name (self,name) :
self.name = name
def set_sound(self, sound):
self.sound = sound
def __str__(self):
return f"name = {self.name} color = {self.color} eat = {self.eat} sound = {self.sound}"
class Cat(Dog):
def __str__(self):
return f"name = {self.name} color = {self.color} eat = {self.eat} sound = {self.sound}"
dog = Dog()
dog.set_name("VAVA")
dog.set_color("red")
dog.set_eat("snack")
dog.set_sound("boo")
cat = Cat()
cat.set_name("Hello")
cat.set_sound("meow")
cat.set_color("blue")
cat.set_eat("tuna")
print(dog)
print(cat)