How Do You Pass a Variable from One Class to Another in Java? -


i have 2 java classes named x.java , y.java.

in x.java have protected method:

protected resultset populatespecieslist(resultset results) 

and inside of protected method, have if statement:

if (fstitle != null) {     sp.setfirestudytitle("available");     string sppacronym = results.getstring("acronym");      firestudyquerybuilder qb = new firestudyquerybuilder();      this.magicstring = qb.buildmagicstring(); } 

now in y.java have method goes this:

string buildmagicstring() {                      string sppacronym = getacronym();      string newquerystring = bunch of sql;      return newquerystring; } 

the problem is, can't use sppacronym in other class because it's not recognized.

so question is, how pass variable class another?

thanks.

can not rewrite method buildmagicstring() following?

string buildmagicstring(string sppacronym) //this allows caller pass argument method. {                       system.out.println(sppacronym); //this statement compile because sppacronym valid member of method.      string newquerystring = bunch of sql;      return newquerystring; } 

then call method follows:

if (fstitle != null) {     sp.setfirestudytitle("available");     string sppacronym = results.getstring("acronym");      firestudyquerybuilder qb = new firestudyquerybuilder();      this.magicstring = qb.buildmagicstring(sppacronym); //passes sppacronym object buildmagicstring() method. } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -