In this we are going to see a basic program of multiple inheritance with constructors in Python Programming Language.
class Parent_class1(object):
# Constructor
def __init__(self, name, id):
self.name = name
self.id = id
# To fetch employee details
def Employee_Details(self):
return self.id, self.name
# To check if this is a valid employee
def Employee_check(self):
if self.id > 500000:
return " Valid Employee "
else:
return " Invalid Employee "
class Parent_class2:
def msg(self):
print("Employee check")
# derived class or the sub class
class Child_class(Parent_class1,Parent_class2):
def End(self):
print(" END OF PROGRAM ")
# Driver code
Employee1 = Child_class("Employee1", 198754) # child class object
Employee1.msg()
print(Employee1.Employee_Details(), Employee1.Employee_check())
Employee2 = Parent_class1("Employee2", 600445) # parent class object
print(Employee2.Employee_Details(), Employee2.Employee_check())
Employee1.End()
# Coded by SAAHIL
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP