Python Programming - Inheritance
Exercise : Inheritance - General Questions
- Inheritance - General Questions
86.
In Python, what is the purpose of the
isinstance()
function?
Answer: Option
Explanation:
The
isinstance()
function is used to check if an object is an instance of a particular class or a tuple of classes.
87.
Consider the following code:
class Vehicle:
def __init__(self, brand):
self.brand = brand
class Car(Vehicle):
def __init__(self, brand, model):
super().__init__(brand)
self.model = model
What is the primary purpose of using super().__init__(brand)
in the Car
class constructor?
Answer: Option
Explanation:
super().__init__(brand)
is used to call the constructor of the superclass Vehicle
and initialize the brand
attribute.
88.
What is the purpose of the
__len__()
method in Python classes?
Answer: Option
Explanation:
The
__len__()
method is used to customize the behavior when the len()
function is called on an instance of the class.
89.
How does Python handle multiple inheritance conflicts for attribute resolution?
Answer: Option
Explanation:
Python automatically resolves attribute conflicts in multiple inheritance by using the attribute defined in the first class.
90.
What is the purpose of the
__slots__
attribute in Python classes?
Answer: Option
Explanation:
The
__slots__
attribute is used to restrict the set of attributes that can be assigned to instances, providing memory optimization.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers