because class members (variables) are usually (and should be) private or protected.
Thus, we use the public set / get method to store and retrieve data from them that otherwise would not be available outside the class.
Giving class members a public place may lead to an unintentional revaluation, so we limit access to prevent this. Read on encapsulation.
/ , .
heres SO.