Getter and Setter Methods in Java...
'getter' is a term for a method that gets the value of a variable, a 'setter' sets the value. That's really all there is to it...
The Example of Getter and Setter method is given below:-
class Clock {
String time;
void setTime (String t) {
time = t;
}
String getTime() {
return time;
}
}
}
class ClockTestDrive {
public static void main (String [] args) {
Cock c = new Clock;
c.setTime("12345")
String tod = c.getTime();
System.out.println(time: " + tod);
}
}
'getter' is a term for a method that gets the value of a variable, a 'setter' sets the value. That's really all there is to it...
The Example of Getter and Setter method is given below:-
class Clock {
String time;
void setTime (String t) {
time = t;
}
String getTime() {
return time;
}
}
}
class ClockTestDrive {
public static void main (String [] args) {
Cock c = new Clock;
c.setTime("12345")
String tod = c.getTime();
System.out.println(time: " + tod);
}
}