Python Programming - Inheritance
Exercise : Inheritance - General Questions
- Inheritance - General Questions
71.
What is the purpose of the
__init_subclass__()
method?
Answer: Option
Explanation:
The
__init_subclass__()
method is used to customize the initialization of subclasses in Python.
72.
Consider the following code:
class Shape:
def __init__(self, color):
self.color = color
class Circle(Shape):
def __init__(self, radius, color):
super().__init__(color)
self.radius = radius
What is the purpose of using super().__init__(color)
in the Circle
class?
Answer: Option
Explanation:
super().__init__(color)
is used to call the constructor of the superclass Shape
and initialize the color attribute.
73.
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
.
74.
How can you achieve method overriding in Python using the
@property
decorator?
Answer: Option
Explanation:
Method overriding in Python can be achieved by using the
@property
decorator on the method in the superclass and implementing it in the subclass.
75.
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