java - Why I am getting null -
can please me solve problem. when try print getcorrectanswer printing null. how can getcorrectanswer print correctanswer thanks.
public class test1 { private string correctanswer; public string getcorrectanswer() { return correctanswer; } public void setupcorrectanswer() { if (1 == 1) { correctanswer = "a"; } else { correctanswer = "d"; } } public static void main(string[] args) { test1 = new test1(); system.out.println(" answer " + a.getcorrectanswer()); } }
you need use setupcorrectanswer()
method set value.
public static void main (string [] args) { test1 = new test1(); a.setupcorrectanswer(); // here system.out.println(" answer " + a.getcorrectanswer()); }
Comments
Post a Comment