The answer is - it depends.
Yes, I would also recommend that you start by making your variables private
, there are cases where this may not be required, but lets stay on subject and only ever allowing access to them via getters
Now assuming your have a public
getter for your instance field, this raises the potentially that some one else will want to override this method and change it in some way, maybe return a calculated value based on new values they have introduced or what ever.
If the private
field is part of any internal calculation or changes the state of the object logic in some way, then you start having problems, as you are now ignoring the value that is returned by the getter, which would produce undesirable results.
In this case, you must consider the value returned by the getter over the private
field.