I\'m from the php world. Could you explain what getters and setters are and could give you some examples?
class Clock {
String time;
void setTime (String t) {
time = t;
}
String getTime() {
return time;
}
}
class ClockTestDrive {
public static void main (String [] args) {
Clock c = new Clock;
c.setTime("12345")
String tod = c.getTime();
System.out.println(time: " + tod);
}
}
When you run the program, program starts in mains,
setTime()
is called by the object c time
is set to the value passed by getTime()
is called by object ctod
and tod
get printed out