As Sebastian said,it is not good Idea to expose a class Instance variable to other class(which is in different package) directly . additionaly , using setter and getter method you can apply some logic before you set the value to a reference/variable and also you can apply synchronization stuff
Joined: Feb 23, 2009
To augment to that, even if your setter/getter does not implement any logic and plainly sets/gets the values, you reserve the possibility to do so later. If you expose instance variables to the outside world, you are forced to do so forever and are hardly able to change your implementation later.
Also, there is no way to control the state of your object. Imagine a public instance variable called weight which takes an int value. If it public you could assign -50 which is an illegal value and puts your object into an inconsistent state.