Monday , December 18 2017
Home / JAVA / Java program for Method overriding

Java program for Method overriding

Overriding is a technique in which we can recreate any function of base class by modifying this function with same name in the derived class.

The function in parent or base class is with same name and must also has same type of arguments if provided in the function of the child class.

Here child class inherited all the functionalists of the Base or Parent class and if the child class wants some type of modification in some function than they could easily modify the functions with same name by their respective modifications or changes in the child class function.

In Simpler terms overriding is the mechanism of recreation of function of base class in the child or derive class.

class Overriding  // Base class name is defined

void Function1() // first function of the base or child class
{    // here we can provide any implementation of the function as required
System.out.println("Hello This is a Function of Base Class"); 
System.out.println("This is first Base class Function");
} //exit of the function also these are instance functions

void Function2() // second function of base class
{ //any type of implementation in the function we use simple printing the statements
System.out.println("This is Base class function "); 

void Function3() // third function of base class
System.out.println("This is Second Base class function");
}// exit of class
class Overriding_child extends Overriding  *

void Function1() // this is override function of base class with same name
System.out.println("This is override function of base class");

void Function4() // simple instance function of child class
System.out.println("This is Simple another function in Derived class");

public static void main(String args[]) // main function

Overriding_child obj=new Overriding_child(); // object is created for child class

obj.Function1(); // override function of child class is called

obj.Function2(); //simple second function of base class

obj.Function3();//simple third function of base class

obj.Function4();//simple second function of child class which is Function4
} // exit of main
}//exit of class

*New class which inherit the functionalists of above defined Overriding class


Also See:   Java program to find saddle point in a matrix
Method overriding in java
Method overriding in java

Incoming terms: overriding in java program.

Check Also

Java program to implement polymorphism

Java program to implement polymorphism: Polymorphism is a technique in java with which you can ...

Leave a Reply

Your email address will not be published. Required fields are marked *