In this program, we have a parent class named Details and two kid classes named Employee and Doctor, we are legacy the class Details on the classes, Employee and Doctor.
Furthermore, at long last making two objects of Employee and Doctor classes and setting, indicating the qualities utilizing their techniques.
Python code to demonstrate an example of single inheritance with two child classes
# Python code to demonstrate example of
# single inheritance with two child classes
class Details:
def __init__(self):
self.__id=0
self.__name=""
self.__gender=""
def setDetails(self):
self.__id=int(input("Enter Id: "))
self.__name=input("Enter Name: ")
self.__gender=input("Enter gender: ")
def showDetails(self):
print("Id: ",self.__id)
print("Name: ",self.__name)
print("Gender: ",self.__gender)
class Employee(Details):
def __init__(self):
self.__company=""
self.__desig=""
def setEmployee(self):
self.setDetails()
self.__company=input("Enter Compmany Name: ")
self.__desig=input("Enter Designation: ")
def showEmployee(self):
self.showDetails()
print("Company: ",self.__company)
print("Designation: ",self.__desig)
class Doctor(Details):
def __init__(self):
self.__hospital=""
self.__dept=""
def setDoctor(self):
self.setDetails()
self.__hospital=input("Enter Hospital Name: ")
self.__dept=input("Enter Department: ")
def showDoctor(self):
self.showDetails()
print("Hospital: ",self.__hospital)
print("Department",self.__dept)
def main():
print("Employee Object: ")
e = Employee()
e.setEmployee()
e.showEmployee()
print("\nDoctor Object: ")
d=Doctor()
d.setDoctor()
d.showDoctor()
if __name__=="__main__":
main()
Output
Employee Object:
Enter Id: 101
Enter Name:Justtechreview
Enter gender: Male
Enter Compmany Name: Justtechreview
Enter Designation: Technical writer
Id: 101
Name: Prem Sharma
Gender: Male
Company: Justtechreview
Designation: Technical writer
Doctor Object:
Enter Id: 201
Enter Name: Justtechreview
Enter gender: Male
Enter Hospital Name: APOLLO
Enter Department: Doctor
Id: 201
Name: Justtechreview
Gender: Male
Hospital: APOLLO
Department Doctor