nerdexam
Oracle

1Z0-808 · Question #32

Which two are benefits of polymorphism?

The correct answer is C. More dynamic code at runtime D. More flexible and reusable code. Polymorphism enables dynamic dispatch - the JVM decides at runtime which method implementation to invoke based on the actual object type, making code inherently more dynamic (C). It also allows you to write general code against a supertype that works with any subtype, producing…

Working with Inheritance

Question

Which two are benefits of polymorphism?

Options

  • AFaster code at runtime
  • BMore efficient code at runtime
  • CMore dynamic code at runtime
  • DMore flexible and reusable code
  • ECode that is protected from extension by other classes

How the community answered

(23 responses)
  • A
    4% (1)
  • B
    9% (2)
  • C
    87% (20)

Explanation

Polymorphism enables dynamic dispatch - the JVM decides at runtime which method implementation to invoke based on the actual object type, making code inherently more dynamic (C). It also allows you to write general code against a supertype that works with any subtype, producing flexible, reusable designs (D).

Why the distractors are wrong:

  • A & B (faster/more efficient): Polymorphism introduces virtual method table lookups at runtime, which adds slight overhead - the opposite of a performance benefit.
  • E (protected from extension): This describes final classes/methods. Polymorphism actually encourages extension - subclasses override behavior precisely to enable it.

Memory tip: Break down the word - poly (many) + morph (forms). Many forms = code that adapts dynamically at runtime and is flexible enough to handle many types. If an answer choice sounds like a performance gain or a restriction, it's a distractor.

Topics

#Polymorphism#Inheritance#Code Reusability#Dynamic Dispatch

Community Discussion

No community discussion yet for this question.

Full 1Z0-808 Practice