what are getters and setters 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: java setter
public setValue(value) {
this.value = value;
}
Example 3: what is static setter and getter examples in java
public class DataHolder{
private static String dataString;
public static String getDataString(){
synchronized(DataHolder.class){
return DataHolder.dataString;
}
}
public static void setString(String dataString){
synchronized(DataHolder.class){
DataHolder.dataString = dataString;
}
}
}