Building blocks Concept Java syntax Class with constructor class Car { Car(String m) { this.model = m; } } Constructor chaining this(...) (same class), super(...) (parent) — must be first statement Inheritance class Truck extends Vehicle — single class inheritance Interface interface Drivable { void drive(); } — a class can implement many Abstract class abstract class Vehicle — cannot be instantiated; may hold state Prevent extension final class, final methods Restrict subclasses sealed interface Shape permits Circle, Square (Java 17+) Nested types static nested, inner, local and anonymous classes Object methods to override toString() for readable output, and equals() + hashCode() together whenever objects are compared or used as map keys. Records generate all three for you. Polymorphism…
Key Takeaways
A class extends one class but can implement many interfaces.
this(...) / super(...) must be the first statement in a constructor.
Override equals() and hashCode() together.
final prevents overriding; sealed restricts which classes may extend.