Oracle
1Z0-809 · Question #218
1Z0-809 Question #218: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-809 to reveal the answer and full explanation for question #218. The question stem and answer options stay visible for context.
Question
Given:
class MyClass implements AutoCloseable {
int test;
public void close() { }
public MyClass copyObject() { return this; }
}
and the code fragment:
MyClass obj = null;
try (MyClass obj1 = new MyClass()) {
obj1.test = 100;
obj = obj1.copyObject(); // line n1
}
System.out.println(obj.test); // line n2
What is the result?
Options
- AAn exception is thrown at line n2.
- B100
- CA compilation error occurs because the try block is declared without a catch or finally block.
- DA compilation error occurs at line n1.
Unlock 1Z0-809 to see the answer
You've previewed enough free 1Z0-809 questions. Unlock 1Z0-809 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.