-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultipleInheritance.py
More file actions
91 lines (67 loc) · 1.42 KB
/
MultipleInheritance.py
File metadata and controls
91 lines (67 loc) · 1.42 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
# A Python program to demonstrate
# inheritance
# Base class or Parent class
class Child:
# Constructor
def __init__(self, name):
self.name = name
# To get name
def getName(self):
return self.name
# To check if this person is student
def isStudent(self):
return False
# Derived class or Child class
class Student(Child):
# True is returned
def isStudent(self):
return True
# Driver code
# An Object of Child
std = Child("Ram")
print(std.getName(), std.isStudent())
# An Object of Student
std = Student("Shivam")
print(std.getName(), std.isStudent())
# Python program to demonstrate
# single inheritance
# Base class
class Parent:
def func1(self):
print("This function is in parent class.")
# Derived class
class Child(Parent):
def func2(self):
print("This function is in child class.")
# Driver's code
object = Child()
object.func1()
object.func2()
# Python program to demonstrate
# multiple inheritance
# Base class1
class Mother:
mothername = ""
def mother(self):
print(self.mothername)
# Base class2
class Father:
fathername = ""
def father(self):
print(self.fathername)
# Derived class
class Son(Mother, Father):
def parents(self):
print("Father :", self.fathername)
print("Mother :", self.mothername)
# Driver's code
m1 = Mother()
m1.mothername = "Pakkeramma"
m1.mother()
f1 = Father()
f1.fathername = "Eranna"
f1.father()
s1 = Son()
s1.fathername = "RAM"
s1.mothername = "SITA"
s1.parents()