Sometimes a subclass inherits a method from a superclass that doesn't quite fit its needs. Perhaps the subclass inherited twenty methods and just one of them wasn't quite right.

In that case, the subclass would override that method by redefining that method itself.

This override does not affect the method as defined in the superclass.

The Cat class in the following example is the subclass and the Animal class is the superclass. The Cat class overrides eat() method inherited from Animal class.

 public class Animal {

    public void eat() {
        System.out.println("Eat for Animal");
    }
}

public class Cat extends Animal {

    public void eat() {
        System.out.println("Eat for Cat");
    }
}