Student.Student_Card obj4 = Student.new Student_Card(namess, idss, true);
学生类是外部类,而Studen_Card是嵌套类,当我运行此代码时,出现以下错误: 需要包含Student.Student_Card的封闭实例
答案 0 :(得分:1)
您需要这样做:
Student.Student_Card obj4 = new Student.Student_Card(namess,idss,true);
答案 1 :(得分:0)
如果要消除错误,请用static
标记内部类,如下所示:static class Student_Card
否则,请注意内部类需要外部类的实例,例如:
Student student = new Student();
Student_Card studentCard = student.new Student_Card()
答案 2 :(得分:0)
如果您的Student_Card
类不是静态的,则需要一个Student实例才能创建它。
Student student = new Student();
Student.Student_Card obj4 = student.new Student_Card(namess, idss, true);
如果您要使`Student_Card类成为静态类,则根本不需要对Student类的任何引用,这将起作用:
Student.Student_Card card= new Student.Student_Card(namess, idss, true);
您可以在this thread中阅读更多内容。