Python Programming - Polymorphism
Exercise : Polymorphism - General Questions
- Polymorphism - General Questions
31.
Which of the following is an example of polymorphism through operator overloading?
Answer: Option
Explanation:
Polymorphism through operator overloading in Python involves defining custom behavior for operators in a class, such as using
__add__()
for the +
operator.
32.
Consider the following code:
class Animal:
def sound(self):
pass
class Dog(Animal):
def sound(self):
return "Woof!"
class Cat(Animal):
def sound(self):
return "Meow!"
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.
33.
How is polymorphism related to the concept of "duck typing"?
Answer: Option
Explanation:
"Duck typing" in Python refers to the ability of objects to take on multiple forms or types based on their behavior, aligning with the concept of polymorphism.
34.
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.
35.
In Python, what is operator overloading?
Answer: Option
Explanation:
Operator overloading in Python involves defining custom behavior for operators in a class, such as using methods like
__add__()
for the +
operator.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers