0
How to call a method from another script within the parameters of a statement?
I had a question on exam that wanted me to call a method from another script, but by doing this I could only do it within the parameter of the method in the script I was in. Example: I kept trying stuff like this cleanUp(otherScript.tokenize); cleanUp(otherScript.tokenize(tokens)); The otherScript method would return an array called tokens and the method cleanUp was suppose to use the array from the other script to form its array within its self
1 Answer
+ 1
your second example is right
import java.util.Arrays;
public class Script {
void cleanUp (String[] tokens){
System.out.println( Arrays.toString(tokens) );
}
String[] tokenize(String tokens) {
return tokens.split("\s");
}
public static void main(String[] args) {
Script script = new Script();
Script otherScript = new Script();
String tokens = "aa bb cc dd ee ff";
script.cleanUp(otherScript.tokenize(tokens));
}
}