CS 121 Lecture Notes - Lecture 21: Instance Variable, Reserved Word
Document Summary
Encapsulation: an important spirit of java is object-oriented, which means object should be self-governing. Object manages its own data (die: facevalue) The instance data (die: facevalue) of an object should be modified. That"s why we put (cid:498)private(cid:499) in front of the instance variables; it prevents the code outside of a class to (cid:498)reach in(cid:499) the data. Data are well-protected w/in the object like a black box. Users can access data through the legal ways defined w/ in the class, only by that object. i. e. , methods also called interfaces. Visibility modifiers: appropriately used to accomplish encapsulation, in. Java; is a reserved word that specifies who can see & use a method or data. Java has 3 visibility modifiers: public, protected, private. Methods or data with public visibility can be referenced anywhere. Methods or data with private visibility can be referenced only within that class. The two components of an object class are data & methods.