Exercise: Python

Questions for: Polymorphism

Which of the following statements about method overloading in Python is correct?
A:
Python supports method overloading with different return types
B:
Python supports method overloading with the same method name but different parameters
C:
Method overloading is not allowed in Python
D:
Python supports method overloading by explicitly specifying the data type of parameters
Answer: C
Python does not support method overloading in the traditional sense as it is done in languages like Java. Methods with the same name in a class will override each other.
In Python, what is polymorphism?
A:
The ability of a class to inherit from multiple classes
B:
The ability of a function to take different types of arguments
C:
The ability of an object to take on multiple forms or types
D:
The ability to create instances of a class
Answer: C
Polymorphism in Python refers to the ability of an object to take on multiple forms or types.
Which of the following are necessary for Run-time Polymorphism?
  1. The overridden base method must be virtual, abstract or override.
  2. Both the override method and the virtual method must have the same access level modifier.
  3. An override declaration can change the accessibility of the virtual method.
  4. An abstract inherited property cannot be overridden in a derived class.
  5. An abstract method is implicitly a virtual method.
A:
1, 3
B:
1, 2, 5
C:
2, 3, 4
D:
4 only
Answer: B
No answer description is available. Let's discuss.
Which of the following can be declared as a virtual in a class?
  1. Methods
  2. Properties
  3. Events
  4. Fields
  5. Static fields
A:
1, 2, 3
B:
3, 5
C:
2, 4
D:
2, 3, 5
Answer: A
No answer description is available. Let's discuss.
In order for an instance of a derived class to completely take over a class member from a base class, the base class has to declare that member as
A:
new
B:
base
C:
virtual
D:
overrides
Answer: C
No answer description is available. Let's discuss.
Ad Slot (Above Pagination)
Quiz