February 2014
Beginner
1248 pages
62h 25m
English
As you’ll see, through the use of set and get methods, you can validate attempted modifications to private data and control how that data is presented to the caller—these are compelling software engineering benefits. We’ll discuss this in more detail in Section 3.5.
If the instance variable were public, any client of the class—that is, any other class that calls the class’s methods—could see the data and do whatever it wanted with it, including setting it to an invalid value.
You might think that even though a client of the class cannot directly access a private instance variable, the client can do whatever it wants with the variable through public set ...
Read now
Unlock full access