Overriding - rahul00773/JavaConcepts GitHub Wiki

Whatever methods parent has by default available to the child through inheritance. If child class not satisfied with parent class implementation then the child is allowed to redefined that method based on its requirement. This process is called overriding. The parent class method which is overridden is called overridden method. And the child class method which is overriding is called overriding method.

class P {

public void property(){

System.out.println(“cash”);
}


public void marriage(){

System.out.println(“Neha b”); // overridden method

}

}


class c extends P{

public void marriage(){. // This process is called overriding

System.out.println(“Neha ”); //overriding method

}

}


class T{
public static void main(String[] args){

//Case 1

 P p = new P();
P.marriage();  // Parent class method

C c = new C(); 
C.marriage // child Class method


P p = new C();

P.marriage(); /// parent class method

}
}```


In overRiding method resolution always takes care By JVM based on a run-time object. And hence overriding is also considered as run time polymorphism or dynamic polymorphism or late binding.