public class D21LX { public static void main(String arge[]){ fish [] a1=new fish[3]; a1[0] = new fish(); a1[1] = new fish(); a1[2] = new fish(); a1[0].name="鱼"; a1[0].type="娃娃鱼"; a1[0].age=0; a1[1].name="鱼1"; a1[1].type="娃娃鱼1"; a1[1].age=1; a1[2].name="鱼2"; a1[2].type="娃娃鱼2"; a1[2].age=2; for(fish y:a1){ System.out.println(y.type); } } } class fish{ String name; String type; int age=10; }
结果:
娃娃鱼
娃娃鱼1
娃娃鱼2
时间: 2025-01-06 03:31:48