CARVIEW |
Python Polymorphism MCQ
Question 1
What will be the output of the following code:
class Square:
def __init__(self, side):
self.side = side
def calculate_area(self):
return self.side ** 2
# What will be the output of the following code?
square = Square(4)
result = square.calculate_area()
print(result)
8
12
16
20
Question 2
What is the purpose of the classmethod decorator in Python, and how does it contribute to polymorphism?
It is used to create a class-level attribute.
It is used to create a method that can be called on the class itself, contributing to polymorphism.
It is used to enforce strict type checking.
It is used to create a read-only attribute.
Question 3
How can you achieve polymorphism through instance methods in Python?
By using function overloading.
By using function overriding.
By using method overloading.
Polymorphism cannot be achieved through instance methods.
Question 4
How does Python support polymorphism through function arguments?
By enforcing strict type checking
By using default arguments.
By using variable-length argument lists and unpacking
By limiting the number of arguments
Question 5
In Python, what is the purpose of the property decorator in the context of polymorphism?
To create a property that cannot be overridden.
To enforce strict type checking.
To achieve polymorphism in functions.
To create a read-only attribute.
Question 6
How can you achieve polymorphism through function overloading in Python?
By defining multiple functions with the same name but different parameters.
By using special methods like __len__ and __str__.
By enforcing strict type checking.
Polymorphism cannot be achieved through function overloading.
Question 7
How does Python handle polymorphism in built-in functions like len() and str()?
By enforcing strict type checking
By using function overloading
By using function overriding
By using special methods like __len__ and __str__
Question 8
What will be the output of the following code:
class Rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
def calculate_area(self):
return self.length * self.width
# What will be the output of the following code?
rectangle = Rectangle(7, 9)
result = rectangle.calculate_area()
print(result)
45
56
63
72
Question 9
What is the key difference between compile-time polymorphism and runtime polymorphism in Python?
Compile-time polymorphism is achieved through function overloading, while runtime polymorphism is achieved through function overriding.
Compile-time polymorphism is achieved through function overriding, while runtime polymorphism is achieved through function overloading.
Compile-time polymorphism is the same as runtime polymorphism in Python.
Compile-time polymorphism and runtime polymorphism are not applicable in Python.
Question 10
What is the role of the super() function in method overriding in Python?
It calls the constructor of the derived class.
It calls the constructor of the base class.
It is used to create a new instance of a class.
It is not used in method overriding.
There are 21 questions to complete.