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

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -