【发布时间】:2014-06-09 21:40:06
【问题描述】:
我是 Java 新手,最近我研究 class 和 object 主题。但是,我无法处理此代码:
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 方法中,我得到了 student 的错误,但没有得到 teacher 的错误。我不知道我是否做错了什么或者我看不到它。必须做什么?
我得到的错误:
- 没有使用局部变量student的值
- 无法访问 ClassStudy 类型的封闭实例。必须 使用 ClassStudy 类型的封闭实例限定分配 (例如 x.new A() 其中 x 是 ClassStudy 的一个实例)。
- 行断点:ClassStudy [line: 44] - main(String[])
【问题讨论】:
-
如果您是 Java 新手,我强烈建议您一开始就不要使用嵌套类。
标签: java eclipse class object methods