Free Online Flashcard Deck

5 Polymorphism and Substitutability Free Online FlashCards

Study 5 Polymorphism and Substitutability with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is polymorphism?

Back

Polymorphism lets code use objects of different concrete types through a shared abstraction while each object supplies its own behavior.

02
Front

How does polymorphism separate client code from implementation?

Back

The calling code depends on the shared type, while the object supplied at runtime determines the specific implementation that runs.

03
Front

What is dynamic dispatch?

Back

Dynamic dispatch, also called late binding, selects an overridable instance method using the object's runtime type.

04
Front

How do overloading and overriding differ?

Back

Overloading is selected mainly from compile-time argument information; overriding selects inherited instance behavior according to the runtime object.

05
Front

What is method overriding?

Back

An overriding method provides a compatible implementation of an inherited instance method with the same operation signature.

06
Front

Why use Java's @Override annotation?

Back

@Override asks the compiler to verify that a method actually overrides an inherited method, catching misspellings or incorrect parameter lists.

07
Front

What does substitutability require?

Back

Substitutability means an object can be used wherever its abstraction is expected without violating the client's expectations.

08
Front

How should a subtype handle preconditions?

Back

A subtype should not require more than the supertype requires; otherwise it may reject inputs that valid client code is allowed to provide.

09
Front

What role does an interface play in polymorphism?

Back

An interface states what clients can request while leaving each implementing class free to determine how the operation is performed.

10
Front

Why accept the narrowest useful type?

Back

Accept the narrowest useful abstraction, such as Notifier instead of EmailNotifier, so the method depends only on the capability it needs.

11
Front

How does composition provide polymorphism?

Back

Composition lets a class contain a strategy object, such as a Formatter, so behavior can vary without creating a subclass hierarchy.

12
Front

Which implementation runs for Shape shape = new Circle(2.0); shape.area();?

Back

The call uses Circle's implementation, because the object is a Circle even though the variable is declared as Shape.