Python Programming - Inheritance
Exercise : Inheritance - General Questions
- Inheritance - General Questions
91.
In Python, what is the purpose of the
issubclass()
function?
Answer: Option
Explanation:
The
issubclass()
function is used to check if a class is a subclass of another class.
92.
Consider the following code:
class Shape:
def __init__(self, color):
self.color = color
class Square(Shape):
def __init__(self, color, side_length):
super().__init__(color)
self.side_length = side_length
What is the primary advantage of using super().__init__(color)
in the Square
class constructor?
Answer: Option
Explanation:
super().__init__(color)
is used to call the constructor of the superclass Shape
and initialize the color
attribute.
93.
In Python, what is the purpose of the
@classmethod
decorator?
Answer: Option
Explanation:
The
@classmethod
decorator is used to define a method that takes the class as its first argument, conventionally named cls
.
94.
How does Python handle method resolution in the presence of diamond inheritance conflicts?
Answer: Option
Explanation:
Python uses the C3 linearization algorithm to determine the method resolution order in the presence of diamond inheritance conflicts.
95.
What is the purpose of the
__call__()
method in a Python class?
Answer: Option
Explanation:
The
__call__()
method in a class is used to customize the behavior when an instance of the class is called, allowing instances to be callable.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers