Question 31

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.)
  • Question 32

    Given the code fragment:

    What is the result?
    Word: why what when
  • Question 33

    Given the code fragment:

    Assume that dbURL, userName, and password are valid.
    Which code fragment can be inserted at line n1 to enable the code to print Connection Established?
  • Question 34

    Given the code fragment:
    public class FileThread implements Runnable {
    String fName;
    public FileThread(String fName) { this.fName = fName; }
    public void run () System.out.println(fName);}
    public static void main (String[] args) throws IOException, InterruptedException { ExecutorService executor = Executors.newCachedThreadPool(); Stream<Path> listOfFiles = Files.walk(Paths.get("Java Projects")); listOfFiles.forEach(line -> { executor.execute(new FileThread(line.getFileName().toString())); // line n1
    });
    executor.shutdown();
    executor.awaitTermination(5, TimeUnit.DAYS);//
    line n2
    }
    }
    The Java Projects directory exists and contains a list of files.
    What is the result?
  • Question 35

    Given the code fragment:
    public static void main (String[] args) throws IOException {
    BufferedReader brCopy = null;
    try (BufferedReader br = new BufferedReader (new FileReader("employee.txt")))
    { //
    line n1
    br.lines().forEach(c -> System.out.println(c));
    brCopy = br; //line n2
    }
    brCopy.ready(); //line n3;
    }
    Assume that the ready method of the BufferedReader, when called on a closed BufferedReader, throws an exception, and employee.txt is accessible and contains valid text.
    What is the result?