Method overriding means writing a method in a child class that has the same name, return type, and parameters as a method in the parent class. The child's version replaces the parent's version when called on a child object.
public class Animal {
void speak() {
System.out.println("Some sound");
}
}
public class Dog extends Animal {
void speak() {
System.out.println("Woof!");
}
}
Now new Dog().speak() prints Woof!, not Some sound. The child's speak() method overrides the parent's.
Overriding is how you customize inherited behavior. The parent defines a general version, and each child provides its own specific version. This is the foundation of polymorphism, which you'll see in a few units.