Python Inheritance Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q11
Can private members be inherited in Python?
  • A Yes, always
  • B No, never
  • C Only if declared as protected
  • D Through name mangling
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?
  • A Order of method execution
  • B Order of class inheritance search
  • C Order of method parameters
  • D Order of method definition
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?
  • A __inheritance__
  • B __mro__
  • C __order__
  • D __resolution__
Answer: Option B
Explanation: The __mro__ attribute or mro() method returns the method resolution order of a class.
Q14
What is hybrid inheritance?
  • A Only multiple inheritance
  • B Only multilevel inheritance
  • C Combination of inheritance types
  • D Only hierarchical inheritance
Answer: Option C
Explanation: Hybrid inheritance is a combination of multiple types of inheritance.
Q15
What is the diamond problem in multiple inheritance?
  • A Memory allocation issue
  • B Ambiguity in method resolution
  • C Syntax error
  • D Import conflict
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?
  • A By ignoring one parent
  • B Using C3 linearization
  • C By random selection
  • D By alphabetical order
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()?
  • A No difference
  • B isinstance for objects, issubclass for classes
  • C isinstance for classes, issubclass for objects
  • D Both work the same
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?
  • A A class with no methods
  • B A class that cannot be instantiated
  • C A class with only variables
  • D A class that imports modules
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?
  • A abstract
  • B abc
  • C base
  • D abstractbase
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?
  • A To make method private
  • B To enforce method implementation in subclasses
  • C To hide method from documentation
  • D To optimize method performance
Answer: Option B
Explanation: @abstractmethod indicates that a method must be implemented by any concrete subclass.
Questions and Answers for Competitive Exams Various Entrance Test