+ 1

"You may validate the given value in the setter before actually setting the value". Explain this?

Getters and setters allow us to have control over the values. You may, for example, validate the given value in the setter before actually setting the value.

3rd Nov 2021, 10:07 AM
NIKHIL JOSHI
NIKHIL JOSHI - avatar
1 Antwort
+ 1
A sample code to set marks: void setMarks(int marks) { if(marks<0 || marks>100) System.out.println("Invalid value to set); //invalid value entered so don't accept to set else this.marks=marks; // else you can set }
3rd Nov 2021, 10:18 AM
Jayakrishna 🇮🇳