Prepin
Log in

Can a subclass in Python inherit from more than one base class?

Approach / Explanation

This question seeks to assess your understanding of inheritance in Python, particularly your awareness that a subclass can inherit from more than one base class. The interviewer is interested in your grasp of Python's ability to manage multiple inheritance. In object-oriented programming, inheritance allows one class to acquire all the attributes (fields) and behaviors (methods) of another class, known as the base class. The class that derives these attributes is called the subclass. To effectively respond to this question, you should clarify whether a subclass can inherit from several base classes in Python, provide a concise explanation of how multiple inheritance operates in Python, if it is indeed possible, and ideally, include an example to illustrate the concept.

Suggested Answer

Indeed, in Python, a subclass has the ability to inherit from multiple parent classes. This feature is known as multiple inheritance and serves as a significant advantage in Python, allowing for improved code reusability and structure. Here’s a straightforward illustration: class Base1 : pass class Base2 : pass class Sub ( Base1 , Base2 ) : pass In this scenario, "Sub" is a subclass that derives attributes from both the "Base1" and "Base2" parent classes.

Alternative Answer

Indeed, Python allows for multiple inheritance, enabling a subclass to inherit from more than one base class. This feature, which permits a subclass to adopt characteristics and functionalities from multiple parent classes, sets Python apart from certain other programming languages. Here’s an illustrative example: class Mother : def __init__ ( self ) : self . eye_color = "brown" self . hair_color = "dark brown" class Father : def __init__ ( self ) : self . height = "6 feet" self . weight = "80 kg" class Child ( Mother , Father ) : def __init__ ( self ) : Mother . __init__ ( self ) Father . __init__ ( self ) my_child = Child ( ) In this example, the "Child" class inherits from two parent classes, "Mother" and "Father." Consequently, the "Child" object possesses attributes from both parents. This capability to inherit properties and methods from multiple classes facilitates the creation of more complex and varied subclasses.

Question Details

Difficulty & Category

Medium
coding

Product

AI Candidate AgentCompaniesBrowse JobsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin | All rights reserved.