Python Programming - Inheritance
Exercise : Inheritance - General Questions
- Inheritance - General Questions
96.
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.
97.
Consider the following code:
class Book:
def __init__(self, title, author):
self.title = title
self.author = author
class EBook(Book):
def __init__(self, title, author, format_type):
super().__init__(title, author)
self.format_type = format_type
What is the primary advantage of using super().__init__(title, author)
in the EBook
class constructor?
Answer: Option
Explanation:
super().__init__(title, author)
is used to call the constructor of the superclass Book
and initialize the title
and author
attributes.
98.
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.
99.
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.
100.
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