Advertisement
elena1234

inheritance and polymorphism in Python

Feb 5th, 2022
1,316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. class Cat():
  2.     def __init__(self, name, age):
  3.          self.name = name
  4.          self.age = age
  5.          
  6.     def eat(self):
  7.         print("Cat is eating...")
  8.        
  9.  
  10. class PersianCat(Cat):
  11.     def __init__(self, name, age):
  12.         super().__init__(name, age)
  13.        
  14.  
  15. class BengalCat(Cat):
  16.     def __init__(self, name, age):
  17.         super().__init__(name, age)
  18.        
  19.  
  20. class SiberianCat(Cat):
  21.     def __init__(self, name, age):
  22.         super().__init__(name, age)
  23.  
  24.  
  25. cat1 = PersianCat("Eli", 3)
  26. print(cat1.name)
  27. cat1.eat()
  28. cat2 = SiberianCat("Mimi", 2)
  29. print(cat2.name)
  30. cat2.eat()
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement