访问nested class需要这样:OuterClass.InnerClass。 你的例子需要这样:People.Student stu = new People.Student();
public static class Student{ public Student(){}}加static描述
People.Student stu = new People.Student();
public class Course{ People p = new People(); People.Student stu = new Student(); p.addNo(stu);//这个算什么,既不是field,也不是method }public class Course{ { People p = new People(); People.Student stu = p.new Student();
p.addNo(stu); } }
public class People { public People() { } public void addNo(Student student) { } public static class Student { public Student() { } } public class Teacher { public Teacher() { } } }public class Course{ public static void main(String []argv){
People p= new People(); People.Student stu = new People.Student(); p.addNo(stu); } } 这样才能编译通过
你的例子需要这样:People.Student stu = new People.Student();
public Student(){}}加static描述
public class Course{
People p = new People();
People.Student stu = new Student();
p.addNo(stu);//这个算什么,既不是field,也不是method
}public class Course{
{
People p = new People();
People.Student stu = p.new Student();
p.addNo(stu);
}
}
} public void addNo(Student student) {
} public static class Student {
public Student() {
} } public class Teacher {
public Teacher() {
} }
}public class Course{
public static void main(String []argv){
People p= new People();
People.Student stu = new People.Student();
p.addNo(stu);
}
}
这样才能编译通过