日期:2014-05-20 浏览次数:20836 次
public class Student { private String id; private String name; private int score; public Student() { } public Student(String id,String name,int score) { this.id = id; this.name = name; this.score= score; } public void setRecord(String id,String name,int score) { this.id = id; this.name = name; this.score = score; } public int getRecord(String id) { if(id.equals(this.id)) return this.score; return 0; } public static void main(String[] args) { Student[] students = new Student[5]; students[0].setRecord("10", "wu", 51); students[1].setRecord("11", "we", 52); students[2].setRecord("12", "ww", 53); students[3].setRecord("13", "wq", 54); students[4].setRecord("14", "wt", 55); int s = 0; for (int i = 0; i < 5; i++) { s= students[i].getRecord("10"); } System.out.println("" + s); } }