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);
}