java - 错误 "No Closing Instance..."

标签 java eclipse class object methods

我是 Java 新手,最近我研究了对象主题。但是,我无法继续执行此代码:

public class ClassStudy {

// Student Group
class Student {

    public String name = null;
    public String surname = null;

    boolean study(boolean does) {
        // He studies.
        boolean d = does;
        return d;
    }
    boolean slackOff(boolean does) {
        // He slacks off.
        boolean d = does;
        return d;
    }
}

// Teacher Group
class Teacher {

    public String name = null;
    public String surname = null;

    boolean teach(boolean does) {
        // He teaches.
        boolean d = does;
        return d;
    }
    boolean learn(boolean does) {
        // He learns.
        boolean d = does;
        return d;
    }
}

// Main Method
public static void main(String[] args) {
    Student student = new Student();
    Teacher teacher = new Teacher();
}

}

在main方法中,我得到了学生的错误,但没有得到老师的错误。我不知道我是否做错了或者我看不到它。必须做什么?

我得到的错误:

  • The value of the local variable student is not used
    • No enclosing instance of type ClassStudy is accessible. Must qualify the allocation with an enclosing instance of type ClassStudy (e.g. x.new A() where x is an instance of ClassStudy).
    • Line breakpoint:ClassStudy [line: 44] - main(String[])

最佳答案

要么将Student(和Teacher)类设为静态,要么将其设为顶级类

static class Student {
   ...
}

关于java - 错误 "No Closing Instance...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23271686/

相关文章:

Java - 计算后打开的进度条

java - 使用 Gson 反序列化元组数组

eclipse - 如何以更有效的方式使用 Eclipse

java - 实例方法: complex numbers

Python 聊天 : delete variables to clean memory in functions?

java - Play Framework 2.5.1 路由和依赖注入(inject)(适用于 Java)

java - 在异步任务之后用另一个 fragment 替换一个 fragment

Eclipse Java EE 插件

Javascript 不添加/删除类

java - 加载不需要的 Java 类