public class ClassArrayDemo { int age; String name; ClassArrayDemo(int age, String name) { this.age = age; this.name = name; } @Override public String toString() { return "[" + name + "," + age + "]"; } public static void main(String[] args) { ClassArrayDemo[] t = new ClassArrayDemo[3]; t[0] = new ClassArrayDemo(18, "zs"); t[1] = new ClassArrayDemo(19, "ls"); t[2] = new ClassArrayDemo(20, "ww"); for (int i = 0; i < t.length; i++) { System.out.println(t[i]); } } }
结果:
[zs,18] [ls,19] [ww,20]
时间: 2024-10-11 23:17:06