What is the difference between method overloading and overriding in Java?

PointOverloadingOverriding
WhereSame class (or subclass)Subclass and parent class
ParametersMust be differentMust be the same
Return typeCan be differentSame (or a subtype)
DecidedAt compile timeAt run time
Also calledCompile time polymorphismRun time polymorphism
class Animal {
    void sound() { System.out.println("..."); }
}

class Dog extends Animal {
    @Override
    void sound() { System.out.println("Woof"); }       // overriding
    void sound(int times) {                              // overloading
        for (int i = 0; i < times; i++) System.out.print("Woof ");
        System.out.println();
    }
}

public class Main {
    public static void main(String[] args) {
        Animal a = new Dog();
        a.sound();
        new Dog().sound(2);
    }
}
Output

Woof
Woof Woof

See Overloading and Inheritance.


Learn more about the similar topics:
Tutorials
Java Classes and Objects
Java Constructors
Java static and this Keywords
Java Encapsulation and Access Modifiers
Java Inheritance
Java Polymorphism
Java Abstract Classes
Exercises & Assignments
Build a BankAccount class
Calculate areas with inheritance and polymorphism
Use a sealed interface and pattern matching
Interview Questions & Answers
What is a class and an object in Java?
What is a constructor in Java?
What is the difference between a constructor and a method in Java?
What is the this keyword in Java?
What is the static keyword in Java?
What is the final keyword in Java?
What are the four pillars of OOP in Java?