Python Polymorphism Questions and Answers
Practice ModeShowing 10 of 25 questions
Q11
What is compile-time polymorphism?
Answer: Option B
Explanation: Compile-time polymorphism is achieved through method overloading, but Python does not support it in traditional sense.
Q12
Which of the following is true about polymorphism in Python?
Answer: Option B
Explanation: Polymorphism in Python is primarily achieved through inheritance and method overriding.
Q13
What is the purpose of the super() function in method overriding?
Answer: Option B
Explanation: The super() function is used to call the parent class method from the child class.
Q14
Which operator overloading method is used for comparison?
Answer: Option B
Explanation: The __eq__ method is used to overload the == operator for comparison.
Q15
What is abstract base class (ABC) in Python?
Answer: Option C
Explanation: ABCs are classes that contain one or more abstract methods and cannot be instantiated directly.
Q16
Which module is used for abstract base classes?
Answer: Option B
Explanation: The abc module provides the infrastructure for defining abstract base classes in Python.
Q17
What is the difference between __str__ and __repr__?
Answer: Option B
Explanation: __str__ is for informal string representation, while __repr__ is for official string representation that should be unambiguous.
Q18
Which decorator is used to define abstract methods?
Answer: Option B
Explanation: The @abstractmethod decorator is used to declare abstract methods in abstract base classes.
Q19
What is operator overloading?
Answer: Option B
Explanation: Operator overloading allows the same operator to have different meanings based on the context.
Q20
Which method is called when an object is created?
Answer: Option B
Explanation: The __init__ method is the constructor that is automatically called when a new object is created.