• Post Reply Bookmark Topic Watch Topic
  • New Topic

calling outside methods and returning something...  RSS feed

 
Everett Chan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all, just have a question about how to proceed with this..

I am calling a method from outside another .java file and i would like it to return an int back to my driver program, what are the steps necessary in order for me to be able to get that int?

Thank you,
E. Chan
 
s mahen perera
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm.. pretty trivial i guess..Assuming the integer is generated by another *java* class.

This is the class which has the integer value u want to pass to another java class..

public class Callee{

public int getInt(){

// do the calculations to get the int...
return i; // suppose i is the int u want to return..

}

This class gets the integer value from the Callee class..

public class Caller{

public static void main(String[] args){

Callee callee = new Callee();
int i = callee.getInt(); // u get the i from here

}


if the integer is not generated by another java class , and if it generated by some C/C++ code, then u will have to use JNI... for which i guess u will have to post the Q to the Forum relating to JNI

Hope this helps



}





}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!