I mean, okay, sometimes there's stuff you want in your class that is strictly for internal use only. Make that private, because you don't want any other class to touch it. Cool.
But then sometimes you set a class variable to be private, and write public getter and setter methods to retrieve and manipulate it. So say you had this:
class bankvault { private int balance; /* Miscellaneous other stuff... */ public int getBalance() { return this.balance; } public void setBalance(int newbalance) { this.balance = newbalance; } }
So now another class would do this to get the balance (assuming you first created a bankvault object named myBankVault.
balance = myBankVault.getBalance();
and this to set it
myBankVault.setBalance(10000000);
How is that an improvement on just declaring the balance variable public and letting other classes just set it directly instead of going through functions? It's sort of like setting up a bank vault, not letting anyone in except one guy named Larry, and Larry will go into the vault and do whatever you want at any time. Maybe there's something I'm missing here, but it doesn't seem like getters and setters and private variables actually do anything but force you to write more code.