For the most part, in the applications that I wrote, if the getter and setter are no more complicated than your examples, you probably want to minimize the code as much as possible for readability, so a shortened approach is very useful. On the other hand, if you are performing more complex logic in getters and setters (for example, checking or parsing of some kind), you need to make sure that no custom class is bypassing your logic.
Also, as Binary Worner notes in a comment, it depends on what you need and what you want. You know the difference between private , protected and public , and thus you also know what you can and cannot do with your class, depending on which one you choose. Which one is "best" depends entirely on what behavior you want (and don't want) to allow other classes to use this one.
source share