-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimal.py
More file actions
30 lines (21 loc) · 770 Bytes
/
Copy pathanimal.py
File metadata and controls
30 lines (21 loc) · 770 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
class Animal:
def __init__(self, name, age):
self.name = name
self.age = age
class Dog(Animal):
def __init__(self, name, age, work):
super().__init__(name, age)
self.work = work
def print_details(self):
print(f'{self.name} is {self.age} years old & it is {self.work}')
class Cat(Animal):
def __init__(self, name, age, work):
# this will initilized the inherited properties from the animal class
super().__init__(name, age)
self.work = work
def print_details(self):
print(f'{self.name} is {self.age} years old & it is {self.work}')
dog = Dog('Sheery', 2, 'Barking')
cat = Cat('Kitty', 4, 'Sleeping')
dog.print_details()
cat.print_details()