-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path25_inheritance.py
More file actions
138 lines (98 loc) · 2.81 KB
/
25_inheritance.py
File metadata and controls
138 lines (98 loc) · 2.81 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# class Employee:
# company = "ITC"
# def show(self):
# print(f"The name of the employee is {self.name} and the salary is {self.salary}")
# class programmer(Employee):
# company = "Infotech"
# def showLang(self):
# print(f"The name is {self.name} and the language he use most is {self.language}")
# a = Employee()
# b = programmer()
# print(a.company ,b.company)
# Multiple Inheritence
# class Employee:
# company = "ITC"
# def show(self):
# print(f"The name of the employee is {self.name} and the salary is {self.salary}")
# class coder:
# language = "py"
# def printlang(self):
# print(f"Out of all he chooses: {self.language}")
# class coderName:
# name = "Rishav"
# def printName(self):
# print(f"Name of the coder is: {self.name}")
# class programmer(Employee , coder ,coderName):
# company = "Infotech"
# def showLang(self):
# print(f"The name is {self.name} and the language he use most is {self.language}")
# a = Employee()
# b = programmer()
# print(b.language)
# b.printlang()
# b.showLang()
# Multi Level Inheritence
# class employee:
# a = 1
# class programmer(employee):
# b = 2
# class manager(programmer):
# c = "Everything is here ..."
# o = employee()
# print(o.a)
# # print(o.b) # Shows error
# # print(o.c) # Shows error
# o = programmer()
# print(o.b)
# print(o.a)
# # print(o.c) # Shows error
# o = manager()
# print(o.b)
# print(o.a)
# print(o.c)
# Super Keyword
# class employee:
# def __init__(self):
# print("Constructor of Employee")
# a = 1
# class programmer(employee):
# def __init__(self):
# print("Constructor of programmer")
# b = 2
# class manager(programmer):
# def __init__(self):
# super().__init__() # basically calls the child class
# print("Constructor of manager")
# c = "Everything is here ..."
# # o = employee()
# # print(o.a)
# # o = programmer()
# # print(o.b)
# o = manager()
# print(o.c , o.b , o.a)
# Decorators
# class Employee:
# a = 1
# @classmethod # Helps to show the class attribute by overridding the values of instance attributes
# def show(cls):
# print(f"the class attribute of a is {cls.a}")
# e = Employee()
# e.a = 45
# e.show()
# Property decorators
class Employee:
a = 1
@classmethod # Helps to show the class attribute by overridding the values of instance attributes
def show(cls):
print(f"the class attribute of a is {cls.a}")
@property
def name(self):
return self.ename
@name.setter
def name(self,value):
self.ename = value
e = Employee()
e.a = 45
e.name = "Rishav"
print(e.name)
e.show()