0 évaluation0% ont trouvé ce document utile (0 vote)
18 vues3 pages
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.
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.
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.
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: