// ==================================================
// STUDY: note about static method hiding
// ==================================================
class Static {
static class Parent {
// static methods can't be an abstract method, WHY?:
// abstract public static void sayHi() { // deosn't compile
public static void sayHi() {
System.out.println("Hi, I'm parent.");
}
}
static class Child extends Parent{
// it also can't be overriden, WHY??
// @Override
public static void sayHi() {
System.out.println("Hi, I'm child.");
}
}
public static void main(String[] args) {
// let's see this example
Child child = new Child();
child.sayHi(); // this prints "Hi, I'm child.", as expected
Parent who = new Child();
who.sayHi();
// but guess who is going to say?
// IT SAYS "Hi, I'm parent."!!!
//
// It's because java deduce which static method to call at compile time using type.
//
// Meaning it can't get the information on Object's class since that's runtime information.
}
}