日期:2014-05-20  浏览次数:20855 次

类的初始化的问题 求指教!
public class HelloWorld {
public static void main(String[] args){
stuScore stu1,stu2,stu3;
stu1 = HelloWorld.stuScore("zhang3",80);


}
class stuScore {
private String name;
private int score;
public stuScore(String Name,int Score){
this.name = Name;
this.score = Score;
}
public String toString(){
return name+score;
}
}
}

------解决方案--------------------
估计你是想问内部类的初始化
因为你的stuScore是非static的,所以需要
HelloWorld hw = new HelloWorld();
stuScore stu = hw.new stuScore("zhang3", 1);

如果内部类是static的话
stuScore stu = new Test.stuScore("zhang3", 1);
------解决方案--------------------
这些东西都去网上搜吧,很多的。
------解决方案--------------------
stu1 = new HelloWorld().new stuScore("zhang3", 80);