New course! Every coder should learn Generative AI!
Try a free lesson+ 1
is setter method is always void? can't we make it int type and return?
4 Answers
+ 8
Conventionally, setters should not return a value. Therefore, it needs to be a void method, because you're not returning anything from it (just initializing the instance variables).
Getters, on the other hand, does return a value.
+ 1
but is it necessary to write void
0
There's no point, the whole idea of a setter is to set a variable value
0
No, setters are like any other function they just have a fancy name