Class variable: public access read-only, but private access r/w

th3falc0n picture th3falc0n · Jan 14, 2013 · Viewed 10k times · Source

In my current project I have a class which stores its Instance in a variable. This Instance should be accesible by all other classes in the project, but it may only be altered by its own class.

How can I achieve this?

Answer

MrSmith42 picture MrSmith42 · Jan 14, 2013

Write a public getter but no public setter. And the field itself private