This might be too big a question, more of a theoretical inquiry...
I hear in every class and tutorial and advisement that it's "better" and "safer" to differentiate data and parts of objects or classes and such into Public and Private functions.
What I wonder is, why? A program can only do what it's told to do. It's not like this anything to do with marauding hordes assaulting your data, it's just a matter of allowing or disallowing certain parts of program being accessed by other parts of the program. But I can't think of any reason why I wouldn't want every part of program accessible from anywhere. What is the good reason not to make every part of a class/object Public?
Not knowing C++, etc. only Java, I shall use Java to provide a (very) contrived example.
Say you've got a program in multiple classes, each of which is in its own file.
You distribute this program to some malevolent, too-smart-for-his-own-good, pimply teenager, like myself.
This hypothetical person, using whatever means, figures out what methods are being used, then writes and compiles a replacement for one of the class files.
The replacement gets loaded like a regular class, and using all the public methods wreaks general havoc in the system, or whatever.
If the methods and variables are private, however, he'd need to replace a class file with important functionality, which would just mess everything up, instead of providing him with a usable vulnerability.
At least, that's how I understand it, anyone who knows better feel free to correct me.
Now that I think about it, someone making a plugin is a much better example.
Eh, Granite beat me to it, and a better explanation too boot. Oh well.