Share Your Feedback

Multiple Choice Questions (MCQs) on Inheritance in Python – OOP Practice

Boost your Python skills with these MCQs on Object-Oriented Programming and Inheritance. Ideal for beginners, students, and job seekers to test and strengthen their understanding of Python OOP concepts.

📝 Multiple Choice Questions

🟢 Beginner

Q1. What is the main purpose of inheritance in Python?

  1. To create multiple objects of a class
  2. To reuse code and extend functionality
  3. To define private methods in a class
  4. To create a new programming paradigm
Answer

To reuse code and extend functionality

Inheritance allows code reuse and method overriding in child classes.


Q2. Which of the following is the correct syntax for inheritance in Python?

  1. class Child inherits Parent:
  2. class Child(Parent):
  3. class Parent -> Child:
  4. class Parent(Child):
Answer

class Child(Parent):

In Python, a child class is defined using the syntax `class Child(Parent):`, where `Child` inherits from `Parent`.


Q3. What is the output of the following code?

class Animal:
    def speak(self):
        print("Animal speaks")

class Dog(Animal):
    pass

d = Dog()
d.speak()
  1. Animal speaks
  2. Dog speaks
  3. Error: **speak()** not defined
  4. Nothing
Answer

Animal speaks

Dog inherits the `speak()` method from Animal.


Q4. What is the output of the following code?

class Parent:
    def __init__(self):
        print("Parent constructor")

class Child(Parent):
    def __init__(self):
        print("Child constructor")

c = Child()
  1. Parent constructor
  2. Child constructor
  3. Parent constructor Child constructor
  4. Error
Answer

Child constructor

The `Child` constructor overrides the `Parent` constructor.


Q5. What is the primary purpose of inheritance in Python?

  1. To improve memory efficiency
  2. To hide implementation details
  3. To enable code reusability
  4. To reduce program complexity
Answer

To enable code reusability

Inheritance helps avoid code duplication by allowing child classes to reuse methods and properties of parent classes.


Q6. Which syntax correctly defines a class `Child` inheriting from `Parent`?

  1. {"class Child extends Parent"=>nil}
  2. {"class Child(Parent)"=>nil}
  3. {"class Child inherits Parent"=>nil}
  4. {"class Child"=>"Parent"}
Answer

class Child(Parent):

In Python, inheritance is denoted by placing the parent class name in parentheses after the child class name.


🟡 Intermediate

Q1. What is the output of the following code?

class Parent:
    def show(self):
        print("Parent")

class Child(Parent):
    def show(self):
        print("Child")

obj = Child()
obj.show()
  1. Parent
  2. Child
  3. Parent Child
  4. Error
Answer

Child


Q2. What is the output of the following code?

class Parent:
    def greet(self):
        print("Hello from Parent!")

class Child(Parent):
    def greet(self):
        print("Hello from Child!")

obj = Child()
obj.greet()
  1. Hello from Parent!
  2. Hello from Child!
  3. Error
  4. No output
Answer

Hello from Child!

The `greet` method is overridden in the `Child` class, so that version is called.


Q3. What does the `super()` function do?

  1. Returns the base class instance
  2. Calls a method from a sibling class
  3. Calls a method from the parent class
  4. Creates a new subclass
Answer

Calls a method from the parent class

`super()` is used to call methods from the parent class, especially in method overrides


Q4. In multiple inheritance, the method resolution order (MRO) follows:

  1. Depth-first search
  2. Breadth-first search
  3. C3 linearization
  4. Random order
Answer

C3 linearization

Python uses C3 linearization to determine the order in which classes are searched when executing a method.


Q5. What does `isinstance(child_obj, Parent)` return?

  1. true
  2. false
  3. TypeError
  4. None
Answer

true

If `child_obj` is an instance of a class derived from `Parent`, `isinstance` will return `True`.


🔴 Advanced

Q1. Which type of inheritance is NOT supported in Python?

  1. Single
  2. Multiple
  3. Cascading
  4. Multilevel
Answer

Cascading

Python supports single, multiple, and multilevel inheritance, but "cascading" is not a recognized inheritance type.


Q2. How do you explicitly call a parent class method from a child class?

  1. Parent.method(self)
  2. self.parent_method()
  3. super().method()
  4. Both A and C
Answer

Both A and C

You can call a parent method using either `Parent.method(self)` or `super().method()`.


Q3. Which statement about private members (e.g., `__var`) in inheritance is true?

  1. They are directly accessible in subclasses
  2. They are inaccessible due to name mangling
  3. They can be accessed using `super()`
  4. They are inherited without name mangling
Answer

They are inaccessible due to name mangling

Private members with double underscores are name-mangled and not directly accessible from subclasses.


Q4. Hybrid inheritance refers to:

  1. Combining multiple types of inheritance
  2. Inheriting from two parent classes
  3. Overriding all parent methods
  4. Using interfaces only
Answer

Combining multiple types of inheritance

Hybrid inheritance is a combination of more than one type of inheritance, like multiple and multilevel.



🧠 Practice & Progress

Explore More Topics

🐣 Python for Beginners

🧠 Python Advanced