Oracle
1Z0-809 · Question #166
Given: class Student { String name; public Student(String name) { this.name = name; } public static void main(String[] args) { Student[] students = new Student[3]; students[1] = new…
The correct answer is C. A NullPointerException is thrown at runtime. You've hit your session limit · resets 10:20pm (America/New_York)
Question
Given:
class Student {
String name;
public Student(String name) {
this.name = name;
}
public static void main(String[] args) {
Student[] students = new Student[3];
students[1] = new Student("Richard");
students[2] = new Student("Donald");
for (Student s : students) {
System.out.println(s + ".name");
}
}
}
What is the result?
Options
- AAn ArrayIndexOutOfBoundsException is thrown at runtime.
- BRichard
- CA NullPointerException is thrown at runtime.
- DCompilation fails.
- Enull Richard Donald
How the community answered
(31 responses)- A13% (4)
- B6% (2)
- C74% (23)
- D3% (1)
- E3% (1)
Explanation
You've hit your session limit · resets 10:20pm (America/New_York)
Community Discussion
No community discussion yet for this question.