Repaso
EspaƱol
Java CoreCoreJV-13

What is the difference between method overloading and overriding?

Options

  1. Overload: same name, new params. Override: subclass replaces (Correct option)
  2. They are just two names for the very same feature
  3. Overloading needs inheritance; overriding works in one class
  4. Overriding changes the parameters; overloading the return type

Answer

Overloading: same name, different parameters in the same class. Overriding: a subclass replaces a parent's method with the same signature

Why

Overloading: several methods with the same name but different parameter lists, e.g. print(int) and print(String). The compiler picks the one that matches at compile time.

Overriding: a subclass provides its own version of an inherited method with the same name and parameters, usually with @Override. The JVM chooses at runtime based on the real object type (polymorphism).

Remember

Overload = same name, different params. Override = replace in a subclass.

Key terms

Practice this question in Repaso