Python Programming - Polymorphism
Exercise : Polymorphism - General Questions
- Polymorphism - General Questions
41.
How is polymorphism related to the concept of "parametric polymorphism"?
Answer: Option
Explanation:
"Parametric polymorphism" in Python refers to defining functions or classes that can operate on different data types, contributing to polymorphic behavior.
42.
Which of the following is an example of polymorphism through method overloading?
Answer: Option
Explanation:
Polymorphism through method overloading in Python involves defining a method with the same name but different parameters in a class.
43.
What is the purpose of the
__len__()
method in Python classes in the context of polymorphism?
Answer: Option
Explanation:
The
__len__()
method is used to customize the behavior when the len()
function is called on an instance of the class, allowing for polymorphic behavior.
44.
What is the purpose of the
__mul__()
method in Python classes in the context of polymorphism?
Answer: Option
Explanation:
The
__mul__()
method is used to customize the behavior when an instance is multiplied by another instance, allowing for polymorphic behavior.
45.
Consider the following code:
class Guitar:
def play(self):
pass
class ElectricGuitar(Guitar):
def play(self):
return "Distorted sound!"
class AcousticGuitar(Guitar):
def play(self):
return "Harmonious sound!"
What concept is demonstrated in this code?
Answer: Option
Explanation:
This code demonstrates method overriding, where the subclasses provide specific implementations for a method defined in the superclass.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers