我是 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/