Static method in Java can be accessed using object instance [duplicate]

In Java static methods are created to access it without any object instance. It makes some sense to me. But recently I came across one strange thing that, static method in Java can also be accessed through its object instance. This looks pretty wierd to me. Does anyone of you know why this feature is provided by Java? Whats the significance of allowing static methods getting accessed with as well as without instance?


A benefit of this is that it allows you to take an instance method and turn it into a static method without having to modify any existing code (other than the class) and thus allowing for backwards compatibility. I've found this useful as many times I've come across utility methods that can be made static - I can just add the static modifier and continue on my way.


Semantically identical. The compiler is smart enough to know what you mean (that is access the static method through the class). IDEs will give you a warning telling you it's bad manners :)

Look at this question for more details. As they say it can be misleading and that's why IDEs will give you a warning.