getter und setter java code example
Example 1: java get set
class Employ
{
public String name; //name of the employ
public String getName() //Get the name
{
return name;
}
public String setName(String newName) //Set the name
{
this.name = newName;
}
}
Example 2: setter&getter java
public class Vehicle {
private String color;
// Getter
public String getColor() {
return color;
}
// Setter
public void setColor(String c) {
this.color = c;
}
}
Example 3: java getter
public getValue() {
return value;
}
Example 4: getter setter
public class Person {
private String name; // private = restricted access
// Getter
public String getName() {
return name;
}
// Setter
public void setName(String newName) {
this.name = newName;