我是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方法中,我得到了学生的错误,但并没有得到老师的。我不知道我是否犯了什么错误,或者我看不到它。必须做些什么?
的错误,我得到:
- 局部变量学生的价值不使用
- 型ClassStudy没有封闭实例访问。必须 通过类型为ClassStudy 的封闭实例(例如x.new A()其中x是ClassStudy的实例)限定分配。
- 线断点:ClassStudy [行:44] - 主(字符串[])
如果您是Java的新手,我会*强烈建议您避开嵌套类来开始。 –