Flashcards

Quick study sessions to strengthen memory and retain key concepts.

Flashcard Study

Java: Instance Methods

Front

How do instance methods enhance data encapsulation?

They allow controlled access and modification of object state. Instance methods encapsulate the logic required to interact with…

View Card →
Flashcard Study

Java: Instance Methods

Front

Why use instance methods to modify object state?

Instance methods ensure changes affect only the specific object. Instance methods are tied to an object instance, meaning…

View Card →
Flashcard Study

Java: Instance Methods

Front

Why put behavior like `lineTotal()` on `CartItem`?

Because the object that owns the relevant state can answer the question most cleanly. When methods live near…

View Card →
Flashcard Study

Java: Inheritance Basics

Front

What are some pitfalls of subclassing in Java?

It can lead to tight coupling and inflexible hierarchies. Subclassing in Java creates a strong relationship between the…

View Card →
Flashcard Study

Java: Inheritance Basics

Front

How can the 'is-a' relationship influence class design in Java?

It guides the hierarchy and helps define subclass relationships. In Java, the 'is-a' relationship is fundamental for creating…

View Card →
Flashcard Study

Java: Inheritance Basics

Front

Why does interfaces in polymorphism matter in this design?

Interfaces define methods that can be implemented by any class, enabling polymorphism. Interfaces allow different classes to implement…

View Card →
Flashcard Study

Java: Inheritance Basics

Front

When should composition be preferred over inheritance?

Prefer composition when a 'has-a' relationship exists. Composition should be used when a class should contain another class,…

View Card →
Flashcard Study

Java: Inheritance Basics

Front

How does Java handle multiple inheritance using interfaces?

Java uses interfaces to achieve multiple inheritance. Java allows a class to implement multiple interfaces, providing a way…

View Card →
Flashcard Study

Java: Inheritance Basics

Front

What does declaring a class as 'final' mean in Java?

A 'final' class cannot be subclassed. Frame the concept in practical terms so you can explain it during…

View Card →
Flashcard Study

Java: Inheritance Basics

Front

How can inheritance violate the Liskov Substitution Principle?

Inheritance can violate Liskov if a subclass alters expected behavior, breaking substitution. The Liskov Substitution Principle states that…

View Card →