forked from CodeKul/Python-Sep-2018-Weekday
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritance.py
118 lines (85 loc) · 1.8 KB
/
Inheritance.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""
class A:
def __init__(self):
self.n = 0
print("init A")
def display(self):
print("Class A")
class B:
def __init__(self):
self.m = 0
print("init B")
def display(self):
print("Class B")
# objB = B()
# objB.m
# objA = A()
# objA.n
class C(A,B):
def __init__(self):
self.o = 0
print("init C")
A.__init__(self)
B.__init__(self)
def display(self):
print("Class C")
B.display(self)
A.display(self)
c = C()
c.display()
class Polygon:
sides = []
def __init__(self,n):
super().__init__()
self.n = n
def inputSides(self):
for n in range(self.n):
side = input("Enter {} side: ".format(n))
self.sides.append(side)
def displaySides(self):
for side in self.sides:
print(side)
# p = Polygon(3)
# p.inputSides()
# p.displaySides()
class Triangle(Polygon):
def __init__(self):
super().__init__(3)
# t = Triangle()
# t.inputSides()
# t.displaySides()
class Rectangle(Polygon):
def __init__(self):
super().__init__(4)
class Square(Rectangle):
# def __init__(self):
# super().__init__()
def inputSides(self):
side = input("Enter side: ")
for n in range(self.n):
self.sides.append(side)
s = Square()
s.inputSides()
s.displaySides()
"""
class A:
def __init__(self):
self.__private__ = 10
self._protected_ = 20
def display(self):
print(self.__private__)
class B(A):
def display(self):
print(self._protected_)
print(self.__private__)
class C(B):
def display(self):
print(self._protected_)
a = A()
# print(a.__private)
a.display()
print(a._protected_)
b = B()
b.display()
c = C()
c.display()