关于setInfo()的问题
问题在注释处程序代码:
public class Score { private int No; private int score; public Score(){ No=1000; score=0; } public Score(int n,int s){ this.No=n; this.score=s; } public void setInfo(int n,int s){ //这个方法有什么用呢,我前面写的构造方法和这个效果是一样的吧 No=n; score=s; } public int getNo(){ return No; } public int getScore(){ return score; } } public class ScoreTest { public static void main(String[] args){ Score [] student=new Score[10]; for(int i=0;i<10;i++){ student[i]=new Score(1000+i,(int)(Math.random()*100)); } for(int i=0;i<10;i++){ System.out.println(student[i].getNo()+"\t"+student[i].getScore()); } } }