I was reading A Programmer’s Guide to Java™ SCJP Certification by Khalid Mughal.
In the Inheritance chapter, it explains that
Inherit
You can override static methods, but if you try to use polymorphism, then they work according to class scope(Contrary to what we normally expect).
public class A {
public static void display(){
System.out.println("in static method of A");
}
}
public class B extends A {
void show(){
display();
}
public static void display(){
System.out.println("in static method of B");
}
}
public class Test {
public static void main(String[] args){
B obj =new B();
obj.show();
A a_obj=new B();
a_obj.display();
}
}
IN first case, o/p is the "in static method of B" # successful override In 2nd case, o/p is "in static method of A" # Static method - will not consider polymorphism