tangokhi
tangokhi

Reputation: 1015

Why singleton getInstance method has to be public static in Java

I am just curious why a Singleton class getInstance (or whatever you want to call it) needs to be public static. It only needs to be static not public if that singleton should only be used with in the same package or is my assumption is incorrect.

Upvotes: 0

Views: 219

Answers (1)

John3136
John3136

Reputation: 29266

If you don't need it public, don't make it public!

As long as you can use it where you need it you'll be fine.

Upvotes: 3

Related Questions