Python Programming - Inheritance
Exercise : Inheritance - General Questions
- Inheritance - General Questions
76.
In Python, what is the purpose of the
__repr__() method in a class?
Answer: Option
Explanation:
The
__repr__() method is used to provide a string representation of the object, often for debugging purposes.
77.
Consider the following code:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
class Employee(Person):
def __init__(self, name, age, employee_id):
super().__init__(name, age)
self.employee_id = employee_id
What is the primary advantage of using super().__init__(name, age) in the Employee class constructor?
Answer: Option
Explanation:
super().__init__(name, age) is used to call the constructor of the superclass Person and initialize the name and age attributes.
78.
What is the purpose of the
@staticmethod decorator?
Answer: Option
Explanation:
The
@staticmethod decorator is used to define a method that does not access instance-specific attributes, making it independent of instance state.
79.
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.
80.
What is the purpose of the
__del__() method in Python classes?
Answer: Option
Explanation:
The
__del__() method is used to customize the behavior when an instance is deleted, allowing cleanup operations.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers