Python Programming - Polymorphism
Exercise : Polymorphism - General Questions
- Polymorphism - General Questions
16.
What is static polymorphism?
Answer: Option
Explanation:
Static polymorphism in Python, also known as compile-time polymorphism, involves resolving method calls at compile-time based on the method signatures.
17.
Which of the following statements about polymorphism in Python is correct?
Answer: Option
Explanation:
Polymorphism in Python is achieved through both method overloading and method overriding.
18.
Consider the following code:
class Shape:
def area(self):
pass
class Triangle(Shape):
def area(self, base, height):
return 0.5 * base * height
class Square(Shape):
def area(self, side):
return side * side
What concept is demonstrated in this code?
Answer: Option
Explanation:
This code demonstrates method overloading, where the subclass methods have the same name but different parameters than the superclass method.
19.
What is the purpose of the
__call__()
method in Python classes in the context of polymorphism?
Answer: Option
Explanation:
The
__call__()
method is used to customize the behavior when an instance is called as a function, allowing for polymorphic behavior.
20.
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.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers