Eclipse报错
The type Hero is already defined
估计你之前已经存在该类了,将类型改个名就好了
比如将Hero改为Herog
No enclosing instance of type h is accessible. Must qualify the allocation with an enclosing
类的静态方法不能初始化内部类,本来Herog放在h里的,运行时报错
这样就ok了
class Herog {
public String name;
public Herog(String name) {
// TODO Auto-generated constructor stub
this.name=name;
}
public void attack(Herog ...heros) {
for (int i = 0; i < heros.length; i++) {
System.out.println( "攻击了"+heros[i].name);
}
}
}
public class h {
public static void main(String[] args) {
// TODO Auto-generated method stub
Herog hh=new Herog("盖伦");
Herog h1=new Herog("xiao");
Herog h2=new Herog("xiao");
hh.attack(h1,h2);
}
}
网友评论