Card 65 / 76: What are the design benefits of using polymorphism? (Choose all that apply.)
A)
Objects can be generalized as return types and method parameters.
B)
Less code needs to be written.
C)
Superclasses and subclasses can be used interchangeably.
D)
Polymorphism allows code to work with many different types of classes that all share some commonality, such as implementing the same interface.
Answer:
A) Objects can be generalized as return types and method parameters.
D) Polymorphism allows code to work with many different types of classes that all share some commonality, such as implementing the same interface.
Previous Card | ← Previous Card Button |
Next Card | → Next Card Button |
Flip Card | Space-Bar |
A is correct because polymorphism allows objects to act as other objects. The other objects are more general forms of the original object.
D is correct because polymorphism also allows different classes that share some common functionality to be treated the same. They must all implement the same interface.
B and C are incorrect.
B is incorrect because less code may be required, but this is not always the case.
C is incorrect because objects can be referenced only in their more general form. An object cannot be used as a more specific object that extends it later.
|