JAVA Encapsulation
JAVA Encapsulation
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 get and set methods.
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:
Example
public class Person {
// Getter
return name;
// Setter
this.name = newName;