Python Inheritance Questions and Answers
Practice ModeShowing 10 of 25 questions
Q11
Can private members be inherited in Python?
Answer: Option D
Explanation: Private members (starting with double underscore) are name-mangled and not directly accessible in child classes.
Q12
What is the Method Resolution Order (MRO) in Python?
Answer: Option B
Explanation: MRO determines the order in which base classes are searched when looking for a method in inheritance hierarchy.
Q13
Which attribute shows the MRO of a class?
Answer: Option B
Explanation: The __mro__ attribute or mro() method returns the method resolution order of a class.
Q14
What is hybrid inheritance?
Answer: Option C
Explanation: Hybrid inheritance is a combination of multiple types of inheritance.
Q15
What is the diamond problem in multiple inheritance?
Answer: Option B
Explanation: The diamond problem occurs when a class inherits from two classes that have a common ancestor.
Q16
How does Python solve the diamond problem?
Answer: Option B
Explanation: Python uses C3 linearization algorithm for MRO to handle the diamond problem.
Q17
What is the difference between isinstance() and issubclass()?
Answer: Option B
Explanation: isinstance() checks if an object is an instance of a class, while issubclass() checks if a class is a subclass of another.
Q18
What is abstract base class (ABC) in Python?
Answer: Option B
Explanation: ABCs are classes that cannot be instantiated and are designed to be inherited by other classes.
Q19
Which module is used for abstract base classes?
Answer: Option B
Explanation: The abc module provides the infrastructure for defining abstract base classes in Python.
Q20
What is the purpose of @abstractmethod decorator?
Answer: Option B
Explanation: @abstractmethod indicates that a method must be implemented by any concrete subclass.