Eclipse報錯
The type Hero is already defined
估計你之前已經(jīng)存在該類了挽荠,將類型改個名就好了
比如將Hero改為Herog
No enclosing instance of type h is accessible. Must qualify the allocation with an enclosing
類的靜態(tài)方法不能初始化內(nèi)部類颓芭,本來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);
}
}