exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 134 discussion

Actual exam question from Oracle's 1z0-808
Question #: 134
Topic #: 1
[All 1z0-808 Questions]

Given:

What is the result?

  • A. null Richard Donald
  • B. Richard Donald
  • C. Compilation fails.
  • D. An ArrayIndexOutOfBoundsException is thrown at runtime.
  • E. A NullPointerException is thrown at runtime.
Show Suggested Answer Hide Answer
Suggested Answer: E 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Tarik2190
Highly Voted 1 year, 11 months ago
Answer is E: class Student{ String name; public Student(String name) { this.name = name; } } public class Test { 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); } } }
upvoted 7 times
...
akbiyik
Most Recent 1 month, 2 weeks ago
Selected Answer: E
The first index of the array are instantiated as 'null' because Student is an object. c Calling the variable of a null object results NullPointerException.
upvoted 1 times
...
iSnover
3 months, 1 week ago
Selected Answer: E
The answer is the letter E, If you try to System.out.print(array[0]) the result will be: null but in this case the for:each loop try to access the first element result in a NullException
upvoted 1 times
...
Ayla
2 years, 2 months ago
Answer is E
upvoted 2 times
...
massigirello
2 years, 4 months ago
If you try to System.out.print(array[0]) the result will be: null but in this case the for:each loop try to access the first element result in a NullException
upvoted 3 times
Harid
2 years, 4 months ago
Yes, printing null is OK, but calling null will result in NullPointerException. s.name is not just printing, it is calling it.
upvoted 2 times
...
...
SamAru
2 years, 6 months ago
Answer is agreed. But not sure why its throwing an null pointer exception. As we know if any method called on null reference it will throw null pointer exception but case here not sure.
upvoted 1 times
nswati2019
2 years, 6 months ago
bcoz array[0] was never initialized and trying to access .name results in exception
upvoted 3 times
...
...
v323rs
2 years, 12 months ago
the correct answer is E Exception in thread "main" java.lang.NullPointerException
upvoted 1 times
...
DJava
3 years, 7 months ago
Answer is E because... s.name throws NullPointerException with the null value, students[0]
upvoted 3 times
...
pawankalyan
3 years, 7 months ago
Ans is E
upvoted 4 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago