Q12: How do Method Overloading and Method Overriding differ?

  • Overloading (Compile-Time / Static Polymorphism): Multiple methods in the same class share the same name but differ in parameter count or parameter types. Return type alone is insufficient.
  • Overriding (Runtime / Dynamic Polymorphism): Subclass provides a specific implementation of a method already declared in its superclass using the @Override annotation. Method signature and return type must match (or be covariant).
Key Takeaways
  • Overloading = Same method name, different parameter signature (Compile-Time).
  • Overriding = Same method signature in child class (Runtime Dispatch).
Knowledge Check

Can you overload a method by changing ONLY its return type in Java?