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);
sts[1] = new Student("B", 80);
// sts[2] left as default
System.out.println(sts[2]);What is printed?
- Acheck_circle
null
- B
B
- C
A
- D
NullPointerException
Explanation
Object arrays default to null. sts[2] was never assigned, so its value is null. Printing it just prints "null".