Learn Java Programming - Introduction to Encapsulation Part 1 Tutorial
This is part one of a two part tutorial on the concept of encapsulation. It is almost impossible to explain the concept of encapsulation with just wording alone. You must first understand the problem that encapsulation resolves. By the end of part two, you should have a good grasp of what encapsulation is. An instance variable is a variable declared in a class that has a separate copy (value) for each object created. In my Instance Variable Tutorial, we saw how we could directly set the values of the instance variables for each object we created. Now what do we do if we want to control what values can be stored in an instance variable? We can use a setter method to set the value of an instance variable. We can get the value of an instance variable by using a getter method. Becoming familiar with getter and setter methods is key to understanding the concept of encapsulation.


















