exam questions

Exam 1z0-809 All Questions

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

Exam 1z0-809 topic 1 question 51 discussion

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

Given:
final class Folder { //line n1
//line n2
public void open () {
System.out.print("Open");
}
}
public class Test {
public static void main (String [] args) throws Exception { try (Folder f = new Folder()) { f.open();
}
}
}
Which two modifications enable the code to print Open Close? (Choose two.)

  • A. Replace line n1 with: class Folder implements AutoCloseable {
  • B. Replace line n1 with: class Folder extends Closeable {
  • C. Replace line n1 with: class Folder extends Exception {
  • D. At line n2, insert: final void close () { System.out.print("Close"); }
  • E. At line n2, insert: public void close () throws IOException { System.out.print("Close"); }
Show Suggested Answer Hide Answer
Suggested Answer: AE 🗳️

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
6c84cb9
5 months, 4 weeks ago
import java.io.IOException; class Folder implements AutoCloseable { public void open() { System.out.print("Open"); } @Override public void close() throws IOException { System.out.print("Close"); } } public class Test { public static void main(String[] args) throws Exception { try (Folder f = new Folder()) { f.open(); } } }
upvoted 1 times
...
6c84cb9
5 months, 4 weeks ago
A and E are correct.
upvoted 1 times
...
shivkumarx
10 months, 2 weeks ago
AE is right AD would be right if the visibility was not reduced to package private
upvoted 1 times
...
asdfjhfgjuaDCV
11 months ago
AD is the correct answer final class Folder implements AutoCloseable { public void open() { System.out.print("Open"); } public final void close() { System.out.print("Close"); } } public class Test { public static void main(String[] args) throws Exception { try (Folder f = new Folder()) { f.open(); } } }
upvoted 1 times
shivkumarx
10 months, 2 weeks ago
Except D does not use public accessibility, and hence will not compile
upvoted 1 times
...
...
steefaand
12 months ago
Selected Answer: AE
A and E are correct.
upvoted 1 times
...
duydn
1 year, 4 months ago
Selected Answer: AE
A & E are correct
upvoted 1 times
...
r1muka5
1 year, 10 months ago
Answers are A and E.
upvoted 1 times
...
WilsonKKerll
2 years, 10 months ago
Answer is A, E.
upvoted 3 times
...
Ajit0110
3 years, 3 months ago
Option A and E are correct. Tested.Here we need to implement AutoCloseable interface while using try-with resources. When we implement Autocloaseable interface, we must all its methods i.e. open and close methods.
upvoted 4 times
mevlt
2 years, 11 months ago
Just close() there is no such method as open() in AutoCloseable
upvoted 1 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