This Python program demonstrates the concept of multiple inheritance by creating a child class, Student, that inherits from two parent classes, PersonalInfo and AcademicInfo. The program collects personal and academic information from the user and then displays the combined student details, including both personal and academic information. Here's an explanation of the program:
When you run this program, it collects and displays a student's personal and academic information by inheriting and using the methods and attributes from both the PersonalInfo and AcademicInfo parent classes. This demonstrates multiple inheritance, where a child class can inherit from multiple parent classes to reuse their attributes and methods.
class PersonalInfo: # parent classe def __init__(self, idn, name, gender, address, contact): self.idn = idn self.name = name self.gender = gender self.address = address self.contact = contact def display_personal_info(self): print("Id : ", self.idn) print("Name : ", self.name) print("Gender : ", self.gender) print("Address : ", self.address) print("Contact : ", self.contact) class AcademicInfo: # parent classe def __init__(self, stream, year): self.stream = stream self.year = year def display_academic_info(self): print("Stream : ", self.stream) print("Year : ", self.year) class Student(PersonalInfo, AcademicInfo): #child class inheriting from both parent classes def __init__(self, idn, name, gender, address, contact, stream, year): # Call constructors of parent classes PersonalInfo.__init__(self, idn, name, gender, address, contact) AcademicInfo.__init__(self, stream, year) def display_student_details(self): self.display_personal_info() self.display_academic_info() idn = input("Enter the ID : ") name = input("Enter the Name : ") gender = input("Enter the Gender : ") address = input("Enter the Address : ") contact = input("Enter the Contact : ") stream = input("Enter the Stream : ") year = input("Enter the Year : ") # Create a Student instance student = Student(idn, name, gender, address, contact, stream, year) # Display student details student.display_student_details()
Enter the ID : 103 Enter the Name : Mithra Enter the Gender : Female Enter the Address : 123 - Main Street Enter the Contact : 9043017689 Enter the Stream : Computer Science Enter the Year : 2023 Id : 103 Name : Mithra Gender : Female Address : 123 - Main Street Contact : 9043017689 Stream : Computer Science Year : 2023
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions