So, as an example, suppose we have an abstract class called Question , this question contains many lines, one for the question itself, one for the answer and two answers sent to the user if he asked the question correctly / incorrectly.
public abstract class Question { private final String question; private final String answer; private final String answerCorrect; private final String answerWrong; }
My question basically is what would be the usual way to initialize all the lines? So far I have compiled 2 versions of how to do this, they have their own weaknesses and weaknesses, and I would like to know if there is some kind of “best coding practice” for this.
Version A
Initialize everything in the constructor.
public abstract class Question {
This seems pretty convenient, the only problem I am facing is that users will not be sure in which order the lines should be.
public class ExampleClass extends Question { public ExampleClass() { super("I think, that the answer", "and that the question", "answer wrong?", "answer right?"); } }
Version B
Do not initialize immediately and wait for the user to do this.
public abstract class Question {
This simplifies the initialization of variables, but strings cannot be final anymore, and this does not guarantee that the user will initialize all of them.
I also thought about letting the child class implement the abstract methods that are called in the Question constructor to initialize all the lines and keep them final , but this version seemed too strange to me.
Are there any other / better ways to do this? Which version should I prefer?
Thanks in advance for your support.