Professional Documents
Culture Documents
1. Introduction to Encapsulation
2. Information Hiding
3. Access control
4. Example
Introduction to Encapsulation
What is Encapsulation?
❑ protected
❑ The protected modifier specifies that the member can
only be accessed within its own package (as with
package-private).
❑ In addition, by a subclass of its class in another package.
❑ package-private:
❑ The data members or methods which are not declared
using any access modifiers i.e. having default access
modifier are accessible only within the same package.
Access Control
Understanding Java Access Modifiers
int x = 5;
int y = x; // x = 5, y = 5
y = 17; // x = 5, y = 17
x = 8; // x = 8, y = 17
Reference semantics (objects)
� reference semantics: Behavior where variables actually store the
address of an object in memory.
panel2
Objects as parameters
� When an object is passed as a parameter, the object is not copied.
The parameter refers to the same object.
� If the parameter is modified, it will affect the original object.
• https://docs.oracle.com/javase/tutorial/