Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Animal():
- def __init__(self, age, name):
- self.age = age
- self.name = name
- def make_sound(self):
- print(f"{self.name} makes a sound.")
- def eat(self):
- print(f"{self.name} eats.")
- class Dog(Animal):
- def __init__(self, age, name):
- super().__init__(age, name)
- self.breed = "Pug"
- def make_sound(self):
- super().make_sound()
- print("Woof woof")
- def display_breed(self):
- print(f"{self.name} is of breed: {self.breed}")
- class Cat(Animal):
- def __init__(self, age, name):
- super().__init__(age, name)
- self.breed = "Persian"
- def make_sound(self):
- super().make_sound()
- print("Meow")
- def display_breed(self):
- print(f"{self.name} is of breed: {self.breed}")
- anim1 = Animal(8, "Felix")
- anim1.make_sound()
- anim1.eat()
- print()
- dog1 = Dog(8, "Rex")
- dog1.make_sound()
- dog1.eat()
- dog1.display_breed()
- print()
- cat1 = Cat(8, "Whiskers")
- cat1.make_sound()
- cat1.eat()
- cat1.display_breed()
- class Bird(Animal):
- def __init__(self, age, name):
- super().__init__(age, name)
- def fly(self):
- print(f"{self.name} flies.")
- class Eagle(Bird):
- def __init__(self, age, name):
- super().__init__(age, name)
- def hunt(self):
- self.fly()
- print(f"{self.name} hunts.")
- eagle1 = Eagle(5, "Ares")
- eagle1.make_sound()
- eagle1.eat()
- eagle1.hunt()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement