Skip to content

Tag: setter

Do…while is not working in input verification

So I’m trying to do an input verification for my program in java, and I’m trying to do that in this setter: But when I call it and put a wrong name, the do…while does not work and the program just continue Here’s where I call it What am I doing wrong? Answer Maybe that’s because in your catch you

Using set and get methods in java

In my programming class, the teacher said we have to implement a class and use get methods but did not mention set methods in the description. Are they always used or should be used together? This is what I’ve written so far: Answer No, setters are not needed at all when implementing immutable classes/objects: Don’t provide “setter” methods — methods

Setter methods or constructors

so far I have seen two approaches of setting a variable’s value in Java. Sometimes a constructor with arguments is used, others setter methods are used to set the value of each variable. I know that a constructor initialises an instance variable inside a class once a class is instantiated using the “new” Keyword. But when do we use constructors