菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
452
0

【Java】No enclosing instance of type XXX is accessible. Must qualify the allocation with an enclosing instance of type XXX(e.g. x.new A() where x is an instance of XXX).的解决办法

原创
05/13 14:22
阅读数 51020
Multiple markers at this line
    - The value of the local variable people is not used
    - No enclosing instance of type TestExtends is accessible. Must qualify the allocation with an enclosing instance of type 
     TestExtends (e.g. x.new A() where x is an instance of TestExtends).

解决方法:看下是不是把类写在了别的类体里面

例如

public class TestExtends {
    public static void main(String[] args) {
        human people = new human();
    }
    
    class human{
        String name;
        
    }
}

正确的写法应该是

public class TestExtends {
    public static void main(String[] args) {
        human people = new human();
    }
}

class human{
    String name;
    
}

这是学面向对象时经常不小心掉的一个坑,特此记录QAQ

发表评论

0/200
452 点赞
0 评论
收藏