在 Helloworld.java 类的 main 函数中,我创建了一个字符串或一个对象。然后,我创建了另一个类 HelloAnotherClass.java。我想将我的变量从 Helloworld main() 传递给 HelloAnotherClass.java 的主函数。
package helloworld;
public class HelloAnotherClass {
public static void main(String[] args) throws IOException, ParseException {
//... for example print passed variables
}
如何使用参数或其他数据结构将变量从 HelloWorld main() 发送到 HelloAnotherClass main(),然后再将其返回到 HelloWorld.java?简而言之,我想使用另一个 java 类的 main() 函数作为 HelloWorld 类中的函数。
那是我写的代码示例
HelloWorld {
/** * @param args the command line arguments */
public static void main(String[] args) {
HelloAnotherClass.main("example");
}
public class HelloAnotherClass {
public static void main(String coming) throws IOException, ParseException {
System.out.println(coming);
}