Python Programming - Polymorphism
Exercise : Polymorphism - General Questions
- Polymorphism - General Questions
46.
How does Python achieve polymorphism through "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.
47.
Which of the following is an example of polymorphism through function overriding?
Answer: Option
Explanation:
Polymorphism through function overriding in Python involves defining a function with the same name in a module, where a subclass provides a specific implementation for the function.
48.
What is the purpose of the
__floordiv__()
method in Python classes in the context of polymorphism?
Answer: Option
Explanation:
The
__floordiv__()
method is used to customize the behavior when an instance is divided using floor division by another instance, allowing for polymorphic behavior.
49.
In Python, what is the purpose of the
__contains__()
method?
Answer: Option
Explanation:
The
__contains__()
method is used to customize the behavior when an item is checked for membership using the in
keyword, allowing for polymorphic behavior.
50.
Consider the following code:
class Animal:
def speak(self):
pass
class Dog(Animal):
def speak(self):
return "Woof!"
class Cat(Animal):
def speak(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.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers