Python Programming - Classes
Exercise : Classes - General Questions
- Classes - General Questions
16.
What does the term "polymorphism" mean in the context of object-oriented programming?
Answer: Option
Explanation:
Polymorphism in object-oriented programming allows objects of different classes to be treated as objects of a common base class. It enables code to work with objects of various types through a common interface.
17.
In Python, what is the purpose of the
@classmethod
decorator in a subclass?
Answer: Option
Explanation:
The
@classmethod
decorator in a subclass is used to define a class method that is specific to the subclass. It can be called on the class and is aware of the subclass.
18.
What is the purpose of the
__eq__
method?
Answer: Option
Explanation:
The
__eq__
method is called when an object is compared for equality using the ==
operator. It allows customizing the behavior of equality checks for objects.
19.
What is the purpose of the
__len__
method?
Answer: Option
Explanation:
The
__len__
method is used to define the behavior of the len()
function on an object. It is commonly implemented for objects that represent sequences, allowing the determination of their length.
20.
In Python, what is the purpose of the
__iter__
method in a class?
Answer: Option
Explanation:
The
__iter__
method is used to initialize an iterator for a class. It should return an object that implements the __next__
method, allowing the class to be used in a for
loop.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers