The only stupid questions are those that don't get asked!
I struggled with this a bit myself when I first started. The best way I can explain is to use a real-world example.
Your computer is made up of all different parts. It has a processor, a video card, a motherboard, etc. All those parts are neatly encapsulated; in other words, you don't have all these parts sticking out. You don't have to go and connect loose wires together to start your computer. Everything is hidden inside the computer case, and you are given a neat little button to push to turn the computer on.
Turning that computer on is more complicated a task than you might imagine. All the different electronics and circuits (which themselves are encapsulated) are getting just the right amount of power to do what they need to do. You don't have to be an electronic engineer to work a computer. You just have to use the interface that the computer gives you. That interface is a button that, when pushed() turns that computer on or off.
Suppose those wires were exposed tho, and you had to connect them manually. Not only is there a bigger chance of making a mistake (crossing the wrong wires) but there's a bigger chance of an accident (two wires getting crossed that weren't supposed to be crossed). This could potentially damage the computer (or the user for that matter
)
When we write object oriented programs, we want our code to act like individual pieces of a whole thing. Just like the computer is made up of parts, we want our program to be made up of parts. And each of those parts might be made up of other smaller parts. We don't want our wires hanging out all over the place, because accidents could happen, or the user could cross the wrong wires and make our program do weird things!
Using access modifiers like public, private and protected, we can help to prevent weird things from happening by only allowing what we want to happen.
example:
If another part of your program wanted to use the class Unchanged, the only thing they would be able to do is read the variable youCantChangeMe by using the readVariable() method. If they tried something like
That would be an error, because youCantChangeMe is private. This essentially protects your variable from being changed without your knowledge, and prevents hard-to-find bugs.
protected gives package-level access and if you're just starting don't worry too much about it right now. Just use private and public. If the class your writing is the only thing that should be manipulating something, keep it private. If you need to give access to data outside your class, use accessor methods (set() and get()).
Hope this helped you out a bit. Keep learning and asking!