下面代码实现了定义一个数组对象
1 public class Student { 2 3 private String username; 4 private int num; 5 6 public Student(String username, int num) { 7 this.username = username; 8 this.num = num; 9 } 10 11 public static void main(String[] args) { 12 Student s[] = new Student[10]; 13 for (int i = 0; i < s.length; i++) { 14 s[i] = new Student(i + "", i); 15 System.out.println(s[i]); 16 } 17 18 } 19 20 public String getUsername() { 21 return username; 22 } 23 24 public void setUsername(String username) { 25 this.username = username; 26 } 27 28 public int getNum() { 29 return num; 30 } 31 32 public void setNum(int num) { 33 this.num = num; 34 } 35 36 @Override 37 public String toString() { 38 return this.num + " " + this.username; 39 } 40 41 }
-
原文:http://www.cnblogs.com/zhjsll/p/4381309.html