Python Programming - Polymorphism
Exercise : Polymorphism - General Questions
- Polymorphism - General Questions
1.
In Python, what is polymorphism?
Answer: Option
Explanation:
Polymorphism in Python refers to the ability of an object to take on multiple forms or types.
2.
Which of the following statements about method overloading in Python is correct?
Answer: Option
Explanation:
Python does not support method overloading in the traditional sense as it is done in languages like Java. Methods with the same name in a class will override each other.
3.
Consider the following code:
class Shape:
def area(self):
pass
class Circle(Shape):
def area(self, radius):
return 3.14 * radius * radius
class Rectangle(Shape):
def area(self, length, width):
return length * width
What is this example illustrating?
Answer: Option
Explanation:
This example illustrates method overriding, where a subclass provides a specific implementation for a method that is already defined in its superclass.
4.
How is polymorphism achieved?
Answer: Option
Explanation:
Polymorphism in Python is achieved through both method overloading (not in the traditional sense) and method overriding.
5.
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.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers