0

I know this would be too basic question but still I requset you guys to answer. As we all know that we can call a static method with object. I am not sure why someone would like to do this. Can someone please explain me a situation where this would be needed?

If this is not needed then why java dont give an error instead of warning for calling a static method using object.

Sandeep Kumar
  • 13,799
  • 21
  • 74
  • 110
  • 2
    See [this answer](http://stackoverflow.com/a/4978063/1344008) for a possible use case. – npe Jun 28 '12 at 11:43
  • 1
    Since all pointers in Java are strongly typed, a pointer to class X provides the same information as naming that class X. So there's no technical "leap" involved, and no additional function is provided. (The method called will correspond to the pointer type, not the object type, if overloaded.) This is all "compiler magic" and is not reflected in the bytecodes (which will call out the literal class name). – Hot Licks Jun 28 '12 at 11:49

1 Answers1

-1
Can someone please explain me a situation where this would be needed?

Let say you have a class named Container. This container will have a method ,say convertOunceToLiter(param). We can use this method even if have not yet make a container instance as a conversion method in some other places.So this method should be defined as static.

Akhi
  • 2,242
  • 18
  • 24