Class method can be invoked by Class or by instance.

When it is invoked by instance, it uses the type of the instance, to figure out, at compile time, which class method to invoke. So the polymorphism would not happen as you think. For static methods, when the static method of the subclasses has the same signature as their superclass, we call it Hiding.

In Java, **private **/ **final **/ static methods can do hiding by static binding.

Other methods are virtual, and can do overriding by dynamic binding.

1. hiding by class methods


class Super {
 static String greeting() { return "Goodnight"; }
 String name() { return "Richard"; }
}
class Sub extends Super {
 static String greeting() { return "Hello"; }
 String name() { return "Dick"; }
}
class Test {
 public static void main(String[] args) {
 Super s = new Sub();
 System.out.println(s.greeting() + ", " + s.name());
 }
}

// Output: Goodnight Dick

2. static final method


class A {
    static final void m1(){}
}

class B extends A {
    static void m1(){}
}

A method can be declared final to prevent subclasses from overriding or hiding it.