Java Program using method overriding
In this program, You will learn how to implement method overriding in java.
class First {
void msg() {
//statement
}
}
class Test extends First {
void msg() {
//statement
}
}
Example: How to implement method overriding in java.
class First {
void msg() {
System.out.println("Parent method is called here");
}
}
class Main extends First {
void msg() {
System.out.println("Child method is called here");
}
public static void main(String args[]) {
Main t = new Main();
t.msg();
}
}
Output:
Child method is called here