Verified Jobs Live
Java Medium Level ~3 min read

When would you choose an interface over an abstract class in Java?

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

Use an interface to define a capability that unrelated classes can implement, such as a payment gateway contract. Use an abstract class when implementations genuinely share state, construction rules, or protected implementation that belongs to a common hierarchy. A class can implement multiple interfaces but extends only one class. Default interface methods can share behavior, but they do not tu an interface into a place for per-instance mutable fields. Favor the smallest useful contract and test implementations against shared behavioral expectations rather than exposing unnecessary inheritance details.