Python Polymorphism Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q11
What is compile-time polymorphism?
  • A Method overriding
  • B Method overloading
  • C Operator overloading
  • D Duck typing
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?
  • A It requires explicit type declaration
  • B It is achieved through inheritance
  • C It only works with built-in types
  • D It prevents code reuse
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?
  • A To create superclass objects
  • B To call parent class methods
  • C To make methods faster
  • D To prevent 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?
  • A __compare__
  • B __eq__
  • C __same__
  • D __check__
Answer: Option B
Explanation: The __eq__ method is used to overload the == operator for comparison.
Q15
What is abstract base class (ABC) in Python?
  • A A class with no methods
  • B A class that cannot be inherited
  • C A class with abstract methods
  • D A class with only static methods
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?
  • A abstract
  • B abc
  • C base
  • D abstractbase
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__?
  • A No difference, they are the same
  • B __str__ is for users, __repr__ is for developers
  • C __str__ is faster than __repr__
  • D __repr__ is only for numbers
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?
  • A @abstract
  • B @abstractmethod
  • C @abstract_class
  • D @must_override
Answer: Option B
Explanation: The @abstractmethod decorator is used to declare abstract methods in abstract base classes.
Q19
What is operator overloading?
  • A Changing operator symbols
  • B Giving special meaning to operators
  • C Creating new operators
  • D Removing operators from language
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?
  • A __new__
  • B __init__
  • C __create__
  • D __start__
Answer: Option B
Explanation: The __init__ method is the constructor that is automatically called when a new object is created.
Questions and Answers for Competitive Exams Various Entrance Test