Free Online Flashcard Deck

8 Inheritance and Object-Oriented Design Free Online FlashCards

Study 8 Inheritance and Object-Oriented Design with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is encapsulation?

Back

Encapsulation combines an object’s state with the methods that operate on it while limiting direct access to its representation.

02
Front

What is an object invariant?

Back

An invariant is a condition that should remain true, such as a bank account balance never becoming negative.

03
Front

Which access level best protects internal state?

Back

Use private fields for implementation details and state that outside code should not modify directly.

04
Front

What does package-private access permit?

Back

Package-private access allows use within the same package, but not by subclasses in another package or unrelated external classes.

05
Front

When is protected access appropriate?

Back

Use protected cautiously for a deliberate subclass extension point; it also permits access within the same package.

06
Front

How do inheritance and composition differ?

Back

Inheritance models an “is-a” relationship, while composition models a “has-a” relationship. A SalariedEmployee is an Employee; a Car has an Engine.

07
Front

Why does a subclass constructor call super(name)?

Back

The subclass constructor calls super(name) to initialize the superclass portion of the object.

08
Front

What is method overriding?

Back

Overriding supplies a subclass implementation with the same method signature and a compatible return type as an inherited instance method.

09
Front

What does @Override verify?

Back

@Override asks the compiler to verify that a method actually overrides an inherited method, catching misspellings and signature mismatches.

10
Front

Which methods cannot participate in ordinary overriding?

Back

A private method is not overridden because it is not inherited; a static method is hidden; and a final method cannot be overridden.

11
Front

What is runtime polymorphism?

Back

Polymorphism lets a general reference such as Employee refer to different specific objects while runtime dispatch selects each object’s overridden method.

12
Front

How does polymorphism simplify employee processing?

Back

A polymorphic loop can call employee.calculatePay() without testing each concrete employee class with if or instanceof.