Oracle
1Z0-809 · Question #244
1Z0-809 Question #244: Real Exam Question with Answer & Explanation
The correct answer is D. [Dog, Cat, Mouse]. See the full explanation below for the reasoning.
Question
Given the code fragments:
public class Test {
List<String> list = null;
public void printValues() {
System.out.print(getList());
}
public List<String> getList() { return list; }
public void setList(List<String> newList) { list = newList; }
}
and
List<String> li = Arrays.asList("Dog", "Cat", "Mouse");
Test t = new Test();
t.setList(li.stream().collect(Collectors.toList()));
t.getList().forEach(Test::printValues);
What is the result?
Options
- Anull
- BA compilation error occurs.
- CDogCatMouse
- D[Dog, Cat, Mouse]
Community Discussion
No community discussion yet for this question.