Python Programming - Polymorphism
Exercise : Polymorphism - General Questions
- Polymorphism - General Questions
11.
What is dynamic polymorphism?
Answer: Option
Explanation:
Dynamic polymorphism in Python refers to the ability of an object to take on multiple forms or types at runtime, often achieved through method overriding.
12.
Which of the following is an example of operator overloading?
Answer: Option
Explanation:
Operator overloading in Python involves defining methods like
__add__()
to provide custom behavior for operators.
13.
Consider the following code:
class Vehicle:
def drive(self):
pass
class Car(Vehicle):
def drive(self):
return "Car is driving"
class Bicycle(Vehicle):
def drive(self):
return "Bicycle is pedaling"
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.
14.
How does Python achieve polymorphism through method overloading?
Answer: Option
Explanation:
Python does not support method overloading in the traditional sense, where multiple methods with the same name have different parameters.
15.
What is the purpose of the
__getitem__()
method in Python classes in the context of polymorphism?
Answer: Option
Explanation:
The
__getitem__()
method is used to customize the behavior when an item is accessed using square brackets on an instance, allowing for polymorphic behavior.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers