CARVIEW |
Python Inheritance MCQ Questions & Answers
Question 1
What is the main advantage of using inheritance in Python?
Reducing code duplication
Creating private methods
Achieving encapsulation
Enhancing code readability
Question 2
In Python, what is a mixin class, and how is it used in multiple inheritance?
A mixin class is a class that cannot be inherited
A mixin class is a class designed to be combined with other classes
A mixin class is a subclass with only abstract methods
A mixin class is a class with no methods
Question 3
How does Python handle circular dependencies in multiple inheritance?
It leads to an infinite loop
Python does not support circular dependencies
It raises a runtime error
Python resolves the dependencies using the method resolution order (MRO)
Question 4
How do you create an instance of the base class from within the derived class in Python?
By using the base() constructor
By using the create_instance() method
By using the __class__ attribute
By using the super().__init__() method
Question 5
In Python, how do you call a method from the base class within a method of the derived class?
Using the call_base keyword
Using the super() function
By creating an instance of the base class
By using the @base decorator
Question 6
What is the purpose of the __bases__ attribute in Python?
It stores the base classes of a class
It stores the derived classes of a class
It is used to access class attributes
It is used to create a new instance of a class
Question 7
How does method resolution order (MRO) work in Python multiple inheritance?
It follows a random order
It follows the order in which classes are defined
It follows the order specified in the __mro__ attribute
It follows the order of base class names in alphabetical order
Question 8
How can you prevent a method in a base class from being overridden in a derived class in Python?
Use the @final decorator
Use the __prevent_override__ keyword
Declare the method as private
Declare the method as static
Question 9
What is the term for creating a new class that inherits from a single base class and adds or modifies functionality?
Class abstraction
Class extension
Class instantiation
Class encapsulation
Question 10
How does encapsulation relate to inheritance in object-oriented programming?
Encapsulation is an alternative to inheritance
Encapsulation and inheritance are unrelated concepts
Encapsulation is a way to achieve inheritance
Encapsulation and inheritance are synonymous
There are 25 questions to complete.