-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inheritance.py
77 lines (53 loc) · 1.28 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
""" Single Inheritance """
# class Person:
# def __init__(self, name, idnum):
# self.name = name
# self.idnum = idnum
# def display(self):
# print(self.name)
# print(self.idnum)
# class Employee(Person):
# def __init__(self, name, idnum, salary, post):
# self.salary = salary
# self.post = post
# Person.__init__(self, name, idnum)
# a = Person('Shivam', 7)
# a.display()
""" Multiple Inheritance """
# class Base1():
# def __init__(self):
# self.str1 = "Shivam"
# print("Base1")
# class Base2():
# def __init__(self):
# self.str2 = "Chand"
# print(" Base2")
# class derived(Base1, Base2):
# def __init__(self):
# Base1.__init__(self)
# Base2.__init__(self)
# print("Derived")
# def display(self):
# print(self.str1, self.str2)
# a= derived()
# a.display()
""" Multilevel Inheritance """
class Base:
def __init__(self, name):
self.name = name
def getName(self):
return self.name
class Child(Base):
def __init__(self, name, age):
super().__init__(name)
self.age = age
def getAge(self):
return self.age
class grandChild(Child):
def __init__(self, name, age, grade):
super().__init__(name, age)
self.grade = grade
def getGrade(self):
return self.grade
g= grandChild("Shivam", 21, 'A')
print(g.getName(), g.getAge(), g.getGrade())