English

Explain multiple inheritance with the help of an example.

Advertisements
Advertisements

Question

Explain multiple inheritance with the help of an example.

Code Writing
Explain
Advertisements

Solution

In multiple inheritance, a child class inherits features from more than one parent class.

class Father(object):
    def father_name(self):
        print("Father: Raj")

class Mother(object):
    def mother_name(self):
        print("Mother: Rani")

class Child(Father, Mother):
    pass

c = Child()
c.father_name()
c.mother_name()

Child can access methods of both Father and Mother.

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

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×