Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. '''
  2. Extending from ABC makes
  3. this class abstract
  4. '''
  5.  
  6. from abc import ABC, abstractmethod
  7.  
  8. class A(ABC):
  9. def __init__(self):
  10. self.a = 40
  11. # Abstract methods have to be annotated
  12. @abstractmethod
  13. def some_method(self):
  14. # abstract methods can, but usually
  15. # don't have an implementation
  16. pass
  17.  
  18.  
  19. class B(A):
  20. def __init__(self):
  21. super().__init__()
  22. self.b = 50
  23.  
  24. # Class B now has to implement
  25. # some_method
  26. def some_method(self):
  27. print('some_method in B')
  28.  
  29. objekt = B()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement