get set it 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: get set
class Thing {
private int secret; // This is a field.
public int Secret { // This is a property.
get {
Debug.Print("Somebody is accessing the secret!");
return secret;
}
set {
Debug.Print("Somebody is writing to the secret!");
secret = value; // Note the use of the implicit variable "value" here.
}
}
}