-
Notifications
You must be signed in to change notification settings - Fork 0
/
tut62.multilevelInheritance.py
75 lines (51 loc) · 1.9 KB
/
tut62.multilevelInheritance.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
#....................................................................................................................
#multiple inheritance
class Employee:
leaves=10
def __init__(self,aname,adegree,aage):
self.name=aname
self.degree=adegree
self.age=aage
def __init__(self):
pass
def printdetails(self):
print(f"this is {self.name} ....studies as {self.degree} student\n in WCE \n is currently {self.age} years old\n")
class Employee:
leaves=11
def __init__(self,aname,adegree,aage):
self.name=aname
self.degree=adegree
self.age=aage
def printdetails(self):
print(f"this is {self.name} ....studies as {self.degree} student\n in WCE \n is currently {self.age} years old\n")
@classmethod
def change_leaves(cls,aleaves):
cls.leaves=aleaves
@classmethod #used as alternative constructor
def from_dash(cls,string):
return cls(*string.split("-"))
@staticmethod
def printplz(string):
print("this is string printing using static method ,"+string)
class Prog(Employee): #here,i have inherited Employee class in Prog class
def goodDay(self):
print("harry wishes you good day\n")
class ProgPRO(Prog,Multi):
def add(self,a,b,c):
self.first=a
self.second=b
self.third=c
print("first string is ",self.first)
print("second string is ",self.second)
print("third string is ",self.third)
harry=ProgPRO("saurabh","CS","21")
larry=ProgPRO("patil","IT","20")
karan=ProgPRO.from_dash("Karan-ENTC-24")
karan.printplz("Saurabh")
#this both r possible here.......
Employee.printplz("Saurabh")
harry.leaves=11
harry.change_leaves(8)
print(harry.leaves)
harry.goodDay()
#....................................................................................................................