0

Student.Student_Card obj4 = Student.new Student_Card(namess, idss, true);

Student class is an outer class and Studen_Card is nested class,when i am running this code i am getting error that: an enclosing instance that contains Student.Student_Card is required

3 Answers3

1

You need to do it like this:

Student.Student_Card obj4 =new Student.Student_Card(namess, idss, true);

Manos Kounelakis
  • 2,848
  • 5
  • 31
  • 55
0

If you want to get rid of the error, mark the inner class with static, as so: static class Student_Card

Otherwise, note that inner classes require an instance of the outer class, like so:

Student student = new Student();
Student_Card studentCard = student.new Student_Card()
Horațiu Udrea
  • 1,727
  • 8
  • 14
0

If your Student_Card class is not static, then you need an instance of Student in order to create it.

Student student = new Student();
Student.Student_Card obj4 = student.new Student_Card(namess, idss, true);

If you will make class `Student_Card static, then you don't need any reference to your Student class at all, this will work:

Student.Student_Card card=  new Student.Student_Card(namess, idss, true);

You can read more in this thread.

Beri
  • 11,470
  • 4
  • 35
  • 57