0% found this document useful (0 votes)
55 views3 pages

Encapsulation: Etl Labs PVT LTD - Java Programming

Encapsulation hides sensitive data by declaring class variables as private and only accessible within the same class. Getter and setter methods that are public allow external classes to access and update a class's private variables. Getter methods return the variable value while setter methods set the value, with both following a convention of get/setVariableName format.

Uploaded by

ETL LABS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views3 pages

Encapsulation: Etl Labs PVT LTD - Java Programming

Encapsulation hides sensitive data by declaring class variables as private and only accessible within the same class. Getter and setter methods that are public allow external classes to access and update a class's private variables. Getter methods return the variable value while setter methods set the value, with both following a convention of get/setVariableName format.

Uploaded by

ETL LABS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Encapsulation

ETL LABS PVT LTD – JAVA PROGRAMMING 167


Encapsulation
The meaning of Encapsulation, is to
make sure that "sensitive" data is hidden
from users. To achieve this, you must:

4 • declare class variables/attributes as


private (only accessible within the
same class)
• provide public setter and getter
methods to access and update the
value of a private variable

ETL LABS PVT LTD – JAVA PROGRAMMING 168


Get and Set
private variables can only be accessed
within the same class (an outside class
has no access to it). However, it is
possible to access them if we provide
public getter and setter methods.

The get method returns the variable 3


value, and the set method sets the value.

Syntax for both is that they start with


either get or set, followed by the name
of the variable, with the first letter in
upper case:

ETL LABS PVT LTD – JAVA PROGRAMMING 169

You might also like