Manager is an Employee, plus extra behavior/dataObject (directly or indirectly)super(...) calls the superclass constructorA single method call — e.earnings() — behaves differently depending on the actual object type at runtime, not its declared reference type. This lets you write general code (loop over Employee) that automatically works correctly for every subclass.
abstract class cannot be instantiated directlyabstract method has no body — subclasses must override itEmployee → SalariedEmployee, HourlyEmployee)final method cannot be overridden by a subclassfinal class cannot be extended at allAvoid calling an overridable instance method from a constructor — the subclass's version may run before the subclass has finished initializing its own fields.
default methods (with a body) and static methodspublic static final constantsDeclare variables/parameters using the interface type (Payable p = new Invoice();) so code stays flexible — any class implementing Payable can be swapped in without changing the calling code.
Prevents a class from being instantiated from outside — common for utility classes (all-static methods) or singleton patterns.
Visible to the class itself, its subclasses (even in other packages), and other classes in the same package — a middle ground between private and public.
| Method | Purpose |
|---|---|
compareTo(other) | negative/0/positive — defines this object's natural order |
Implement this to let Collections.sort() sort your own class.
| Method | Purpose |
|---|---|
compare(a, b) | defines an external/custom ordering |
Pass a Comparator when you need an ordering different from the class's natural one.