Java Method Overriding:
We can use the Eclipse IDE for this example. If you do not know about it then follow this link- How to Install Eclipse For Java and create a program in it. |
If the subclass (child class) has the same method as declared in the superclass (parent class), it is known as method overriding in Java. In other words, if a subclass provides the specific implementation of the method provided by one of its parent classes, it is known as method overriding.
Note:-
- Method overriding occurs in two classes that have an inheritance relationship.
- In case of method overriding, the parameter must be the same.
- It is an example of run-time polymorphism.
- The return type must be the same or covariant in method overriding.

class Animal
{
public void show() {
System.out.println("The animal speaks");
}
}
class Cat extends Animal
{
@Override
public void show() {
super.show();
System.out.println("The Cat Mew...Mew...");
}
}
public class Method_overriding {
public static void main(String[] args) {
// TODO Auto-generated method stub
// Animal animal = new Animal();
Cat cat = new Cat();
cat.show();
}
}
Comments (No)