Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from abc import ABC, abstractmethod
- class Shape(ABC): #superclass also Shape class is inheriting from ABC module
- @abstractmethod #decorator,it makes the methods below them abstract
- def area():pass
- @abstractmethod #decorator and we dont want the user to create an instance of shape class
- def perimeter(self):pass
- class Square(Shape):#subclass
- def __init__(self, side):
- self.__side = side
- def area(self):
- return self._side * self._side
- def perimeter(self):
- return self._side *4
- shape = Square(5)
- print(shape.area)
- print(shape.perimeter)
- OUTPUTS:
- <bound method Square.area of <__main__.Square object at 0x00000183E34E6108>>
- <bound method Square.perimeter of <__main__.Square object at 0x00000183E34E6108>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement