-1

This is where i am getting error

Student[] student = new Student[10];

System.out.println(" Test : " + student[2].RollNo);

But i do not get error when

Student student = new Student();

System.out.println(" Test : " + student.RollNo);

Error only shows up when i am creating array of objects.

Amith
  • 730
  • 6
  • 22

1 Answers1

0

You have created an array with 10 slots that can contain Student object. You have not, however, put a student into the third slot hence the NPE