java - Passing a string between voids -


i'm new java , i'm not sure if ask question right. have 2 voids, in second 1 string , want use main void. code that:

public void oncreate(bundle savedinstancestate) {  shuffle();  //here want use string correctanswer } public void shuffle() {  string correctanswer = "whatever"; } 

if want use string calculated in second function, why use void?

public void oncreate(bundle savedinstancestate) {     string s = shuffle();     //use s; }  public string shuffle() {     string correctanswer = "whatever";     return correctanswer; } 

you make correctanswer instance variable:

private string correctanswer;  public void oncreate(bundle savedinstancestate) {     shuffle();     //use instance variable correctanswer; }  public void shuffle() {     correctanswer = "whatever"; } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -