NEW
Font size
WorksheetsOOP - Polymorphism in Python
Total questions: 10
Worksheet time: 5mins
What does the word polymorphism literally mean in Greek?
One shape
Many forms
Single type
Multiple loops
In the given Python example, what is the name of the method used in all four classes?
calculate()
run()
operate()
execute()
Which type of polymorphism is demonstrated in the code snippet?
Compile-time polymorphism
Runtime polymorphism
Static method overloading
Function overloading
In the Divide class, what does the code do when b equals zero?
Returns infinity
Prints None
Prints an error message
Skips the operation silently
Why is polymorphism useful in the given code?
It removes the need for loops
It allows the same method name to have different implementations
It automatically converts numbers to strings
It speeds up execution time
How does the for loop in the snippet demonstrate polymorphism?
It checks each object’s class before calling its method
It calls operate() without caring about the object type
It executes only the Add class method
It prevents division by zero
What OOP principles are strongly supported by polymorphism in this example?
Recursion and Iteration
Abstraction and Encapsulation
Inheritance and Compilation
Casting and Parsing
Which of the following is NOT a benefit of using polymorphism?
Easier code extension
Improved maintainability
Reduced type-checking conditions
Increased number of if statements
In the analogy given, polymorphism is compared to:
A Swiss army knife
A universal remote
A toolbox
A smartphone
If we wanted to add a new operation, such as exponentiation, what should we do according to polymorphism principles?
Modify all existing classes
Create a new class with the operate() method
Add a case statement in the loop
Replace the for loop with multiple if statements
