Why use a constructor in intialize and not Setter
I just took beginning java oop and what I don't understand is why use a no-arg constructor to initialize a variable instead why not use a setter method(setLength of field private variable). I can understand using a constructor that sends arguments to initilize when you create a new object from a program. Does the variable have to be initialized?
Re: Why use a constructor in intialize and not Setter
One can use either approach, neither is mandatory. If an instance variable must have a specific value dictated by the state of the caller when the instance is created, passing that value to the constructor makes perfect sense. Otherwise, instance variables can be left to default values or initialized to specific values other than defaults in the no-argument constructor. Any mix of these possible approaches is acceptable.
Instance variables are initialized by default according to specific rules that you can find online. Local variables are not initialized by default and must be initialized by the program.