0

我试图让 Team Roster 和 Coach 类显示输出,但是,当我运行程序时它不会产生输出。它只产生一流的,但在那之后,没有输出显示。

public class Team {
    public static void main(String[] args) {
        String team_name = "Team Georgia";
        System.out.println(team_name);
    }
    //Team Roster
    public class Player {
        public void main(String[] args) {
            String[] first_name = {"Jack","Dave","Henry","John","David","Bob","Tony","Malcolm","Hiro","Jack","Jesus","Luck","Ben", "Benny", "Caboose", "Michael","Taylor","Mark","Hiroshida","Jack","Patric","Davin"};
            String[] last_name = {"Le","lynth","Luther","Kendral","Larry","John","Dave","Grendal","Lee","Lyn","Susan","Solo","Holmes","Stark","Potter","Welma","Han","Smith","Solo","Weasly","Emma","Bones"};
            String[] position = {"Front","Front","Front","Front","Side","Side","Side","Back","Back","Side","Front","Front","Front","Front","Side","Side","Side","Back","Back","Side","Mid","Mid"};
            for ( int i = 0; i < first_name.length; i++ ) {
                //System.out.print("First name: " + first_name[i]+ "\t\t" + " Last name: " + last_name[i] + "\t\t\t" + " Position: " + position[i] + "\n" );
                System.out.println("First name: " + first_name[i]);
                System.out.println("Last name: " + last_name[i]);
                System.out.println("Position: " + position[i]);
            }
        }   
    }
    
    //Coach
    public class Coach {
        public void main(String[] args) {
            String[] first_name = {"Brown","Dave","Jack","King"};
            String[] last_name = {"Jun","Jac","Frost","Kong"};
            String[] title = {"Head Coach", "Assistant Coach", "Offensive Coordinator", "Defensive Coordinator"};
            for ( int i = 0; i < first_name.length; i++ ) {
                //System.out.print("First name: " + first_name[i]+ "\t\t" + " Last name: " + last_name[i] + "\t\t\t" + " Position: " + title[i] + "\n" );
                System.out.println("First name: " + first_name[i]+ " Last name: " + last_name[i] + " Position: " + title[i]);
            }
        }
    }
}
4

1 回答 1

0

Player 和 Coach 类是内部类,其中 Team 是主要的 Public 类,您的文件也将仅以 Team 类的名称 (Team.java) 保存。所以只调用了 Team 类的 main() 方法,为了运行嵌套类的 main 方法,还需要分别对它们进行分类。

由于您的嵌套类不是静态的,要调用嵌套类的 main() 方法,您首先需要创建一个 Team 类的对象,然后引用其他嵌套类对象并从该对象调用 main 方法。

例如,

new Team().new Player().main(args);
new Team().new Coach().main(args);
于 2020-08-29T21:50:58.780 回答