Free Online Flashcard Deck

10 Inheritance and Polymorphism Free Online FlashCards

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

12 cards
01
Front

What are a superclass and a subclass?

Back

The superclass is the existing parent or base class; the subclass is the more specialized child or derived class.

02
Front

What does `extends` declare in Java?

Back

The `extends` keyword declares that one Java class inherits from another class.

03
Front

How does a subclass call a superclass constructor?

Back

A subclass constructor can call a superclass constructor with `super(...)`, initializing state defined by the superclass.

04
Front

What is method overriding?

Back

Method overriding occurs when a subclass supplies a new implementation of an inherited instance method with the same name and compatible parameters.

05
Front

How do overloading and overriding differ?

Back

Overloading defines methods with the same name but different parameter lists; overriding replaces inherited behavior in a subclass.

06
Front

What does polymorphism allow?

Back

Polymorphism lets a superclass reference or parameter refer to objects of multiple compatible subclass types.

07
Front

What is dynamic method dispatch?

Back

Dynamic method dispatch selects an overridden instance method according to the object's runtime type, not merely its declared reference type.

08
Front

What is upcasting?

Back

Upcasting assigns a subclass object to a superclass reference; it is safe and automatic because the subclass satisfies the superclass type.

09
Front

When can a downcast fail?

Back

A downcast is valid only when the object is actually an instance of the target subtype; otherwise Java can throw `ClassCastException`.

10
Front

What is an abstract class?

Back

An abstract class cannot be instantiated directly and may declare abstract methods that subclasses must implement.

11
Front

Are static methods overridden?

Back

Static methods are hidden rather than overridden in the runtime-dispatch sense used for instance methods.

12
Front

When is composition preferable to inheritance?

Back

Composition models a has-a relationship: one object contains or delegates work to another, such as a `Car` containing an `Engine`.