🔌 Interfaces & Abstraction
12 Java concepts, each explained step by step with real code, a common trap and practice questions.
- Interfaces as contractsWhat a type can do, not how; implements.
- Implementing multiple interfacesA class can implement many interfaces.
- Interface constantsFields are implicitly public static final.
- Default methodsInterface methods with a body; enable API evolution.
- Diamond conflictsTwo defaults with the same signature must be resolved with X.super.m().
- Static & private interface methodsHelpers in interfaces; static ones are not inherited by implementers.
- Abstract class vs interfaceState and constructors vs multiple inheritance of type.
- Functional interfacesExactly one abstract method; @FunctionalInterface.
- Marker interfacesSerializable, Cloneable and why annotations often replace them.
- Programming to an interfaceList<String> list = new ArrayList<>() and loose coupling.
- Comparable as an interface exampleNatural ordering via compareTo.
- Sealed classes & interfacessealed + permits restrict who can extend; final, sealed, non-sealed subclasses.