【发布时间】:2012-10-04 11:44:11
【问题描述】:
在我的 Helloworld.java 类的主函数中,我创建了一个字符串或一个对象。然后,我创建了另一个类 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);
}
【问题讨论】: