Advertisement
chegehus

Area_Perimeter11

Feb 22nd, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. from abc import ABC, abstractmethod
  2. class Shape(ABC): #superclass  also Shape class is inheriting from ABC module
  3.     @abstractmethod #decorator,it makes the methods below them abstract
  4.     def area():pass
  5.    
  6.     @abstractmethod #decorator   and we dont want the user to create an instance of shape class
  7.     def perimeter(self):pass
  8.    
  9.    
  10. class Square(Shape):#subclass
  11.     def __init__(self, side):
  12.         self.__side = side
  13.     def area(self):
  14.         return self._side * self._side
  15.     def perimeter(self):
  16.         return self._side *4
  17.        
  18. shape = Square(5)
  19. print(shape.area)
  20. print(shape.perimeter)
  21. OUTPUTS:
  22. <bound method Square.area of <__main__.Square object at 0x00000183E34E6108>>
  23. <bound method Square.perimeter of <__main__.Square object at 0x00000183E34E6108>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement