+ 1
Getter and Setter Methods
Give a description to write a getter and setter method
2 Antworten
+ 3
If you read the chapter, it'll tell you how to write the getter/setter methods. However, I'll try to explain it a bit.
Basically, when you have a class you'll have private members of the class that you don't want people directly accessing. Setters are methods that you can call from the object in order to change those private variables without directly accessing them. The Getters are methods you can use to indirectly return the value of those variables. This is called encapsulation and it helps you keep those variables hidden away.
Hope that helps out some with understanding what they are.
EXAMPLE:
private String name;
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
+ 1
Thank u for your input!!