Python Polymorphism Questions and Answers
Practice ModeShowing 10 of 25 questions
Q1
What is polymorphism in Python?
Answer: Option A
Explanation: Polymorphism allows methods to do different things based on the object it is acting upon.
Q2
Which of the following is an example of method overriding in Python?
Answer: Option B
Explanation: Method overriding allows a subclass to provide a specific implementation of a method that is already defined in its parent class.
Q3
What is duck typing in Python?
Answer: Option B
Explanation: Duck typing focuses on the behavior of objects rather than their actual type.
Q4
Which built-in function demonstrates polymorphism in Python?
Answer: Option B
Explanation: The len() function can work with different data types like strings, lists, tuples, etc.
Q5
What is method overloading in Python?
Answer: Option A
Explanation: Python does not support traditional method overloading like other languages, but we can achieve similar functionality using default arguments or variable-length arguments.
Q6
Which operator overloading method is used for addition?
Answer: Option C
Explanation: The __add__ method is used to overload the + operator in Python.
Q7
What is the main advantage of polymorphism?
Answer: Option B
Explanation: Polymorphism makes code more flexible and reusable by allowing the same interface for different data types.
Q8
Which concept allows the + operator to work with both numbers and strings?
Answer: Option B
Explanation: Operator overloading allows the same operator to behave differently with different data types.
Q9
What is runtime polymorphism in Python?
Answer: Option B
Explanation: Runtime polymorphism is achieved through method overriding where the method call is resolved at runtime based on the object type.
Q10
Which method is used for string representation of an object?
Answer: Option B
Explanation: The __str__ method returns a human-readable string representation of an object.