Java Tutorial · Revision notes
Java Inheritance & Polymorphism
Inheritance lets a class reuse the members of another class. Polymorphism lets the same method call behave differently depending on the actual object. This chapter covers inheritance, method overriding, the super keyword, runtime polymorphism and the final keyword.
Quick revision
- Inheritance uses extends and gives IS-A relationship and code reuse.
- Supported with classes: single, multilevel, hierarchical; multiple inheritance through interfaces only.
- Parent constructor runs first; private members are not accessible in the child; constructors are not inherited.
- Overriding: same signature, covariant return, no weaker access, no broader checked exceptions.
- static, private and final methods cannot be overridden.
- super: parent field, parent method, parent constructor (first statement).
- Dynamic dispatch: methods follow the object; fields and static methods follow the reference.
- final: constant variable, no-override method, no-extend class; final reference can still change object state.