Advertisement
Guest User

AbstractClass

a guest
Nov 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. from abc import ABC, abstractmethod
  2.  
  3. class AbstractClass(ABC):
  4.  
  5.     def __init__(self, value):
  6.         self.value = value
  7.         super().__init__()
  8.  
  9.     @abstractmethod
  10.     def eat(self):
  11.         pass
  12.  
  13. class Parents(AbstractClass):
  14.     def eat(self):
  15.         return "eat solid food "+ str(self.value) + " times each day"
  16.  
  17. class Babies(AbstractClass):
  18.     def eat(self):
  19.         return "Milk only "+ str(self.value) + " times or more each day"
  20.  
  21. food = 3    
  22. mom = Parents(food)
  23. print("moms ----------")
  24. print(mom.eat())
  25.  
  26. infant = Babies(food)
  27. print("infants ----------")
  28. print(infant.eat())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement