Advertisement
simeonshopov

Inheritence example

May 28th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. class Rectangle:
  2.     def __init__(self, length, width):
  3.         self.length = length
  4.         self.width = width
  5.  
  6.     def area(self):
  7.         return self.length * self.width
  8.  
  9.     def perimeter(self):
  10.         return 2 * self.length + 2 * self.width
  11.  
  12. # Here we declare that the Square class inherits from the Rectangle class
  13. class Square(Rectangle):
  14.     def __init__(self, length):
  15.         super().__init__(length, length)
  16.  
  17. square = Square(4)
  18. print(square.area())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement