Difference between interface and abstract class in Java?
Tests understanding of OOP abstraction mechanisms in Java and how their distinction has evolved.
Key differences:
- Interface: multiple inheritance supported, all fields are
public static final, methods default topublic abstract(Java 8+ allowsdefault/staticmethods; Java 9+ allowsprivatemethods) - Abstract class: single inheritance, can have instance fields, constructors, and methods of any visibility; use when sharing state or partial implementation
Rule of thumb: prefer interfaces to define contracts/capabilities; use abstract classes when common state or template-method patterns are needed.
Version-specific follow-ups: Java 8 default methods blurring the line, Java 9 private interface methods, sealed classes (Java 17) restricting hierarchies.
asked …