1z0-809 Exam Question 156

Given:
class ImageScanner implements AutoCloseable {
public void close () throws Exception {
System.out.print ("Scanner closed.");
}
public void scanImage () throws Exception {
System.out.print ("Scan.");
throw new Exception("Unable to scan.");
}
}
class ImagePrinter implements AutoCloseable {
public void close () throws Exception {
System.out.print ("Printer closed.");
}
public void printImage () {System.out.print("Print."); }
}
and this code fragment:
try (ImageScanner ir = new ImageScanner();
ImagePrinter iw = new ImagePrinter()) {
ir.scanImage();
iw.printImage();
} catch (Exception e) {
System.out.print(e.getMessage());
}
What is the result?
  • 1z0-809 Exam Question 157

    Given the code fragment:

    What is the result?
  • 1z0-809 Exam Question 158

    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?
  • 1z0-809 Exam Question 159

    Given the code fragment:

    Which modification enables the code to print Price 5 New Price 4?
  • 1z0-809 Exam Question 160

    Given the code fragments:
    public class Book implements Comparator<Book> {
    String name;
    double price;
    public Book () {}
    public Book(String name, double price) {
    this.name = name;
    this.price = price;
    }
    public int compare(Book b1, Book b2) {
    return b1.name.compareTo(b2.name);
    }
    public String toString() {
    return name + ":" + price;
    }
    }
    and
    List<Book>books = Arrays.asList (new Book ("Beginning with Java", 2), new book ( "A
    Guide to Java Tour", 3));
    Collections.sort(books, new Book());
    System.out.print(books);
    What is the result?