I want to understand on why is it legal to call static methods via instance (object reference)? Say "myObjRef.myStaticMethod()", is allowed, but how does it work? A static method is at class level and hence the confusion i have.
Well this is merely another syntax "objectinstatnce.mystatic method".You see the compiler know that the method you are calling is static and its equivalent to calling "myclassname.mystaticmethod".So the both can be used in place of one another without the compiler making any noise about it.
In one previous Java version (was it 1.3?) it was even allowed to use invalid array indexing like this:
Now that will throw an exception as expected, but technically that exception isn't necessary - only the reference type (A) is needed, not the actual reference.
subject: Calling static methods via object reference