Flashcards

Quick study sessions to strengthen memory and retain key concepts.

Flashcard Study

Java: Interfaces

Front

How do interfaces improve testability and substitution in Java?

Interfaces allow for easy swapping of implementations. Interfaces enhance testability by allowing the use of mock implementations in…

View Card →
Flashcard Study

Java: Interfaces

Front

How would you explain a marker interface in an interview?

An interface with no methods, used to mark classes with metadata. A marker interface does not contain any…

View Card →
Flashcard Study

Java: Interfaces

Front

How do you resolve conflicts with default methods from multiple interfaces?

Override the conflicting method in the implementing class. When a class implements multiple interfaces with default methods of…

View Card →
Flashcard Study

Java: Interfaces

Front

Why does default methods in interfaces matter in this design?

Allows interfaces to have method implementations. Default methods enable interfaces to provide a default implementation of methods, which…

View Card →
Flashcard Study

Java: Interfaces

Front

How does using interfaces promote loose coupling?

Interfaces separate the definition of capabilities from their implementation. Loose coupling means components in a system are independent…

View Card →
Flashcard Study

Java: Interfaces

Front

Why are interfaces important for multiple inheritance?

Interfaces provide a way to achieve multiple inheritance. Java does not support multiple inheritance with classes due to…

View Card →
Flashcard Study

Java: Interfaces

Front

How would you explain an interface in a Java interview?

A contract that defines capabilities without implementation. An interface in Java specifies a set of methods that a…

View Card →
Flashcard Study

Java: Interfaces

Front

When is an interface usually a better fit?

When different classes need the same behavior contract without one shared base state model. Interfaces are strongest when…

View Card →
Flashcard Study

Java: Instance Methods

Front

Why move stock level checks inside the Product class?

Encapsulating stock checks within Product centralizes data management and logic. By placing stock level checks within the Product…

View Card →
Flashcard Study

Java: Instance Methods

Front

Why should the line total calculation be an instance method in CartItem?

It encapsulates the behavior with related data and ensures consistency. Instance methods like calculating a line total directly…

View Card →