Why should we have a private static Java method?

343    Asked by alexGONZALEZ in Java , Asked on Oct 6, 2022

I just wanted to clear up a question I have. What is the point of having a private static method as opposed to a normal method with private visibility?


I would have thought an advantage to having a static method is that it can be called without an instance of a class, but since it's private is there even a point to it being static?


The only reason I can think of is that it helps conceptually understand the method on the class level as opposed to object level.

Answered by Alastair McDade

The characteristic of benign private static java is independent of the visibility.


The reasons that you will want to have a static method (some code that does not depend on non-static members) will still be useful. But maybe you don't want anyone/anything else to use it, just your class.



Your Answer

Interviews

Parent Categories