【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).的解决办法

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

原文地址:https://www.cnblogs.com/syxy/p/9813174.html