Method Hiding in Java Definition -

Redefining super class static method in subclass is called method hiding. In the below given example static method m1() is available in both A and B class i.e called method Hiding.

//A.java

class A {
static void m1() {
System.out.println(" class A static method ");
}
void m2() {
System.out.println("class A non-static method");
}
}


//B.java

class B extends A {
static void m1() {
System.out.println(" class B m1 method");
}
void m2() {
System.out.println(" class B m2 method");
}
}

//Test.java

class Test {
public static void main(String[] args) {
A a = new B();
a.m1();
a.m2();
}
}
Output -

class A static method
class B m2 method