Java looks up what type this object is (how it is declared) and calls that classes static function. Callig a static function on an object reference type works, but it's ... let's say bad coding. You could end up with somewhat upredictable results. See example below. Both objects in memory are actualy ducks, but it outputs
this means although we can use an object reference to call a static method we should not because in case we use polymorphic forms of reference variables that could create confusion ... i suppose this is all that you meant my friend
hmmm ... even i was like "feeling the same" but as the book said you can only call a static method the classname.methodName() way so i went on to check it ...
Lalit Mehra wrote:the book said you can only call a static method the classname.methodName() way
If a book said that, the book is definitely wrong.
Is it possible that the book said you should only call a static method that way? Because that's a matter of opinion, but it's an opinion I and many others agree with.