Overriding

  • Example of Polymorphism

Overriding Constraints

  • https://www.baeldung.com/java-method-overload-override
  • Method signature must match
  • Return Type
    • If base is void, overridden must be void
    • If base is primitive, overridden must be same primitive
    • If base is certain type, overridden must be same type or subtype
      • aka covariant return type
  • Throws clause
    • If base throws exception, overridden must throw same exception or subtype of exception