JAVA小练习50——整体与部分

    xiaoxiao2022-07-03  120

    class Player{ int num; String name; public Player(int num,String name){ this.num = num; this.name = name; } public void play(){ System.out.println(name+"开始训练..."); } } class Team{ String name; //球队的名字 Player p1; //球员1 Player p2; //球员1 Player p3; //球员1 public Team(String name,Player p1,Player p2,Player p3){ this.name = name; this.p1 = p1; this.p2 = p2; this.p3 = p3; } public void startPlay(){ System.out.println(name+"开赛了..."); } } class Demo50 { public static void main(String[] args) { Player p1 = new Player(10,"梅西"); Player p2 = new Player(11,"内马尔"); Player p3 = new Player(7,"C罗"); Team t = new Team("恒大",p1,p2,p3); t.startPlay(); System.out.println("3号球员的名字:"+t.p3.name ); } }
    最新回复(0)