-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperSingleInheritance.py
61 lines (44 loc) · 1.42 KB
/
SuperSingleInheritance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class Rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return self.length * self.width
def perimeter(self):
return 2 * self.length + 2 * self.width
# class Square:
# def __init__(self, length):
# self.length = length
# def area(self):
# return self.length * self.length
# def perimeter(self):
# return 4 * self.length
# Here we declare that the Square class inherits from the Rectangle class
# class Square(Rectangle):
# def __init__(self, length):
# super().__init__(length, length)
# class Cube(Square):
# def surface_area(self):
# face_area = super().area()
# return face_area * 6
# def volume(self):
# face_area = super().area()
# return face_area * self.length
# Super() with Parameters
class Square(Rectangle):
def __init__(self, length):
super(Square, self).__init__(length, length)
class Cube(Square):
def surface_area(self):
face_area = super(Square, self).area()
return face_area * 6
def volume(self):
face_area = super(Square, self).area()
return face_area * self.length
square = Square(4)
print('Square: %i' % square.area())
rectangle = Rectangle(2, 4)
print('Rectangle: %i' % rectangle.area())
cube = Cube(3)
print('Cube: %i' % cube.surface_area())
# print('Cube: %i' % cube.area())