English

What is multiple inheritance? Explain with an example.

Advertisements
Advertisements

Question

What is multiple inheritance? Explain with an example.

Code Writing
Explain
Advertisements

Solution

Multiple inheritance occurs when one derived class inherits from two or more base classes.

class Student(object):
    def student_info(self):
        print("Student details")

class Teacher(object):
    def teacher_info(self):
        print("Teacher details")

class School(Student, Teacher):
    pass

s = School()
s.student_info()
s.teacher_info()

Here, School inherits methods from both Student and Teacher.

shaalaa.com
  Is there an error in this question or solution?
Chapter 4: Inheritance - EXERCISE [Page 77]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 4 Inheritance
EXERCISE | Q 4. | Page 77
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×