Python Polymorphism Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q1
What is polymorphism in Python?
  • A Ability to take multiple forms
  • B Ability to hide implementation details
  • C Ability to inherit from multiple classes
  • D Ability to restrict access to methods
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?
  • A Defining __init__ method in a class
  • B Using the same method name in parent and child class
  • C Using different method names for similar operations
  • D Creating multiple methods with same name in same class
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?
  • A Checking object type before method calls
  • B If it looks like a duck and quacks like a duck, it is a duck
  • C Strict type checking at compile time
  • D Automatic type conversion between objects
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?
  • A type()
  • B len()
  • C id()
  • D isinstance()
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?
  • A Multiple methods with same name but different parameters
  • B Multiple methods with different names but same parameters
  • C Changing method behavior at runtime
  • D Hiding method implementation from user
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?
  • A __plus__
  • B __sum__
  • C __add__
  • D __append__
Answer: Option C
Explanation: The __add__ method is used to overload the + operator in Python.
Q7
What is the main advantage of polymorphism?
  • A Faster execution
  • B Code flexibility and reusability
  • C Smaller code size
  • D Automatic memory management
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?
  • A Method overriding
  • B Operator overloading
  • C Method overloading
  • D Inheritance
Answer: Option B
Explanation: Operator overloading allows the same operator to behave differently with different data types.
Q9
What is runtime polymorphism in Python?
  • A Method overloading
  • B Method overriding
  • C Operator overloading
  • D Function overloading
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?
  • A __repr__
  • B __str__
  • C __string__
  • D __display__
Answer: Option B
Explanation: The __str__ method returns a human-readable string representation of an object.
Questions and Answers for Competitive Exams Various Entrance Test