Python Programming - Inheritance
Exercise : Inheritance - General Questions
- Inheritance - General Questions
16.
What is the purpose of the
@classmethod
decorator?
Answer: Option
Explanation:
The
@classmethod
decorator is used to define a class method, which is a method that is bound to the class and not the instance of the class.
17.
What is the difference between composition and inheritance?
Answer: Option
Explanation:
Inheritance is the mechanism by which one class can inherit attributes and methods from another class, while composition involves containing objects of other classes within a class.
18.
What is the role of the
__bases__
attribute in a Python class?
Answer: Option
Explanation:
The
__bases__
attribute is a tuple containing the base classes of a class, allowing you to inspect the inheritance hierarchy.
19.
What is the purpose of the
@staticmethod
decorator?
Answer: Option
Explanation:
The
@staticmethod
decorator is used to define a static method in a class, which is a method that belongs to the class rather than an instance.
20.
What is the purpose of the
__mro__
attribute?
Answer: Option
Explanation:
The
__mro__
attribute is a tuple containing the method resolution order of a class, showing the order in which base classes are searched when resolving methods.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers