JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
Method overriding is sub class (here class B) providing a new implementation of already present method (non static) in the super class(here class A).
the importatnt thing of methos overriding is there should be a relationship between the two classes to achieve method overriding and it can be done only on non static method. The method name should be same as well as the number and sequence of arguments
*/
class A{
void abc(){
System.out.println("Method abc() of class A");
}
}
class B extends A{
void abc(){
System.out.print("Method abc() of class B");
}
}
public class Program
{
public static void main(String[] args) {
A a1= new A();
a1.abc();
B b1=new B();
b1.abc();
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run