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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -