Overriding::
if want to know first understand what exactly is overriding
executing a method which you wish on account of a method which has been defined in the super class.
As you must be knowing that to implement overriding concept we need to inherit the class
the method defined in the subclass has the same signature as that in the super class, the subclass method overrides the superclass method
/*Here we have a class overRidingOne with a method display.
* we want to display the output according to our requirement.
*/
class overRidingOne
{
private int i,j;
overRidingOne(int a, int b)
{
i = a;
j = b;
}
void display()
{
System.out.println("i and j " + i + j);
}
}
/*the class overRidingTwo is extended to implement the display function of the super class i.e. overRidingOne*/
class overRidingTwo extends overRidingOne
{
private int k;
overRidingTwo( int a, int b,int c) //constructor to accept the values
{
super(a,b); //value of a&b are passed to the super class constructor
k = c;
}
/* as we want to implement the overriding attribute, so we need to declare the method with same return type, same name and same parameters.
*/
//this display will override the display method of overRidingOne class
void display()
{
System.out.println("k " + k);
}
}
public class OverRiding {
/**
* @param args
*/
public static void main(
String[] args) {
// TODO Auto-generated method stub
// instantiating the overRidingTwo class and assigning the values
overRidingTwo overObj = new overRidingTwo(5,6,7);
/* calling display method which will override the display of overRidingOne and provide the output of overRidingTwo*/
overObj.display();
}
}
Hope this helps to clear the doubt