Answer the question
In order to leave comments, you need to log in
Why is the variable displayed correctly when called from one class, but displayed as null when called from another?
The question related to the same IQ test (you can see it in my other questions), now ran into such a problem that by calling a variable int testAnswer
that is in the Question class from the UserInterface class, we get the normal value of the variable, but if we call the same variable from the ResultOfTest class, we get zero, what's wrong, please tell
me The text of the function from the UserInterface class
public void actionPerformed(ActionEvent e) {
Question quest = new Question();
radioButtonChoose();
res.reca();
System.out.println("usinabc"+res.abc);
System.out.println("usintes"+quest.tes);
res.testAnswer(radButt);
res.result();
System.out.println(res.resultOfIQ);
quest.nextQuestion();
setMyInterface();
}
public void reca(){
Question quest = new Question();
System.out.println("ReOftes = "+quest.tes);
abc = quest.tes;
System.out.println("ReOfabc = "+abc);
}
Answer the question
In order to leave comments, you need to log in
Hello. What means
call the same variable from the ResultOfTest class?
reca()
gives the wrong result because you create a new class object in it Question
, it has nothing to do with any of your other variables. And zero because the type class field int
(in your case testAnswer
) is initialized to zero by default.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question