setters and getters java code example
Example 1: java get set
class Employ
{
public String name;
public String getName()
{
return name;
}
public String setName(String newName)
{
this.name = newName;
}
}
Example 2: java setter
public setValue(value) {
this.value = value;
}
Example 3: getters and setters javascript
let obj = {
log: ['a', 'b', 'c'],
get latest() {
if (this.log.length === 0) {
return undefined;
}
return this.log[this.log.length - 1];
}
};
obj.log.push('d');
console.log(obj.latest);
Example 4: java getter
public getValue() {
return value;
}