美文网首页
java常用报错

java常用报错

作者: 小西奥 | 来源:发表于2018-07-10 07:57 被阅读0次

    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);
    }
    

    }

    相关文章

      网友评论

          本文标题:java常用报错

          本文链接:https://www.haomeiwen.com/subject/rvgxpftx.html