Java Encapsulation
This activity demonstrates how encapsulation is used in Java. The program will display the employee's name, employee_id, department, and full-time status (boolean = true). Two Java clases (src) were created, Main and Employee. Also, getter and setter methods are used to access the private variables.
Encapsulation is defined as the wrapping up of data (variables and methods) under a single unit. The variables of a class will be hidden from the other classes, and can only be accessed through the members of the current class. In other words, this OOP method acts as a protective shield that prevents the data from being accessed by the code outside this shield.
- Declare the variables of a class private.
- Create getter and setter methods to modify your private attributes/variables.
- Create a separate main method to test the object.
- Provides code security through data hiding.
- Reusability.
- Flexibility (Read-only or Write-only).
**Intellij IDE community edition is used.