Font Awesome Icons

Tutorial

Method Overriding in Java

Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes. When a method in a subclass has the same name, same parameters or signature and same return type(or sub-type) as a method in its super-class, then the method in the subclass is said to override the method in the super-class.

 

class Parent

{    

 

void show()

{      

System.out.println(“Parent’s show()”);      

}          

 }  

class Child extends Parent

{         

void show()     

{     

System.out.println(“Child’s show()”);

}          

 } 

public class Main

{   

            public static void main(String[] args)    

{                 

Child c = new Child();        

c.show();    

}

}