Free Online Flashcard Deck

4 Inheritance Free Online FlashCards

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

12 cards
01
Front

What is inheritance in object-oriented programming?

Back

Inheritance defines a new class from an existing class, allowing it to receive accessible members, add members, or change inherited behavior.

02
Front

What are the two main class roles in inheritance?

Back

The base class is the existing superclass or parent; the derived class is the new subclass or child that inherits from it.

03
Front

When is composition preferable to inheritance?

Back

Inheritance should model an is-a relationship. Composition is usually better when one object merely contains or uses another, such as a Car having an Engine.

04
Front

What does Bicycle inherit from Vehicle?

Back

Bicycle is a Vehicle, so Bicycle can reuse Vehicle's inherited speed field and stop() method while adding gear and changeGear().

05
Front

What does transitive inheritance mean?

Back

Inheritance is transitive: if MountainBike derives from Bicycle and Bicycle derives from Vehicle, MountainBike also receives Vehicle's inherited behavior.

06
Front

Are constructors generally inherited?

Back

Constructors are generally not inherited. A derived constructor initializes its own state and may invoke a base-class constructor.

07
Front

What does specialization mean in inheritance?

Back

Specialization lets a derived class represent a more specific form of the base concept by adding behavior or details that distinguish it.

08
Front

What is method overriding?

Back

Overriding replaces an inherited instance method with a compatible implementation in the derived class, such as Dog replacing Animal.speak() with “Bark.”

09
Front

How do overriding and overloading differ?

Back

Overriding changes inherited behavior in a derived class; overloading defines methods with the same name but different parameter lists.

10
Front

How can an override extend base behavior?

Back

In Java, super can call the base implementation from an overriding method before the derived method adds its own behavior.

11
Front

What is polymorphic use of a derived object?

Back

Polymorphism allows a derived object to be used where its base type is expected, while the runtime object determines which override runs.

12
Front

What determines an overridden method at runtime?

Back

Runtime dispatch selects the method implementation according to the object's runtime type, so an Animal reference holding a Dog calls Dog's speak().