Function overriding is just easy to say if sub class or child class has the same method or function declared in the parent class that types of method is called function or method overriding.
Declaring a method in subclass (child class) which function is already declared in parent class is known as method overriding.
For Example:-
/**
*
* @author pradeep
*/
class HumanBeing
{
{
public void social()
{
System.out.println("Human is eating");
}
}
class Boy extends HumanBeing{
public void social(){
System.out.println("Boy is eating");
}
public static void main( String args[])
{
{
Boy obj = new Boy();
obj.social();
}
}
Result:Result of this program is
run:
Boy is eating
BUILD SUCCESSFUL (total time: 0 seconds)
Note: If you have any problem then reply me.
No comments:
Post a Comment