Why do we need private static java methods?

510    Asked by SamFraser in Java , Asked on Oct 18, 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?


Answered by Sally Langdon

The characteristic of being static is independent of the visibility.


The reasons that you will want to have a private static java 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