setter method of bean


When we can initialize/assign the field values of a class within constructor right like below

sample constructor of Persons object
public Persons(String last, String first, int i)
lastNm = last;
firstNm = first;
age = i;

If this is the case why we need setter methods. I can understand we need to getter to retrieve back those values. please advise
Who is Participating?
Bijay DeoGraduate Student Research AssistantCommented:
Suppose you want to change the age of the person object after it you create it, how are you going to do that? In that case, the setter method helps to change the age of the person.
Mark BullockQA Engineer IIICommented:
Setter methods are used after the object is created.
You can use a setter to set values initially after you create the object or to change the values.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.