Question 16

Given the code fragment:

What is the result?
  • Question 17

    Given the code fragments:
    class ThreadRunner implements Runnable {
    public void run () { System.out.print ("Runnable") ; }
    }
    class ThreadCaller implements Callable {
    Public String call () throws Exception {return "Callable"; )
    }
    and
    ExecutorService es = Executors.newCachedThreadPool ();
    Runnable r1 = new ThreadRunner ();
    Callable c1 = new ThreadCaller ();
    // line n1
    es.shutdown();
    Which code fragment can be inserted at line n1to start r1and c1 threads?
    Future<String> f1 = (Future<String>) es.submit (r1);
  • Question 18

    Given the code fragment:
    List<String> str = Arrays.asList ("my", "pen", "is", "your', "pen");
    Predicate<String> test = s -> {
    int i = 0;
    boolean result = s.contains ("pen");
    System.out.print(i++) + ":");
    return result;
    };
    str.stream()
    . filter(test)
    . findFirst()
    . ifPresent(System.out ::print);
    What is the result?
  • Question 19

    Given:

    What is the result?
  • Question 20

    Given:
    class Vehicle {
    int vno;
    String name;
    public Vehicle (int vno, String name) {
    this.vno = vno,;
    this.name = name;
    }
    public String toString () {
    return vno + ":" + name;
    }
    }
    and this code fragment:
    Set<Vehicle> vehicles = new TreeSet <> ();
    vehicles.add(new Vehicle (10123, "Ford"));
    vehicles.add(new Vehicle (10124, "BMW"));
    System.out.println(vehicles);
    What is the result?