class Student {
String name; int score;
Student(String n, int s) { name = n; score = s; }
}
Student[] sts = new Student[3];
sts[0] = new Student("A", 90);
System.out.println(sts[1].name);What happens?
- A
ArrayIndexOutOfBoundsException
- B
Prints null
- C
Prints A
- Dcheck_circle
NullPointerException
Explanation
sts[1] is null (default for object array). Accessing .name on null throws a NullPointerException.