Question 21

Given that these files exist and are accessible:

and given the code fragment:

Which code fragment can be inserted at line n1to enable the code to print only /company/emp?
Stream<Path> stream = Files.list (Paths.get ("/company"));
  • Question 22

    Which two reasons should you use interfaces instead of abstract classes?
  • Question 23

    Given the code fragment:
    BiFunction<Integer, Double, Integer> val = (t1, t2) -> t1 + t2;//line n1
    System.out.println(val.apply(10, 10.5));
    What is the result?
  • Question 24

    Given:
    public class product {
    int id; int price;
    public Product (int id, int price) {
    this.id = id;
    this.price = price;
    }
    public String toString() { return id + ":" + price; }
    }
    and the code fragment:
    List products = new ArrayList(Arrays.asList(new Product(1, 10),
    new Product (2, 30),
    new Product (2, 30));
    Product p = products.stream().reduce(new Product (4, 0), (p1, p2) ->
    { p1.price+=p2.price;
    return new Product (p1.id, p1.price);});
    products.add(p);
    products.stream().parallel()
    .reduce((p1, p2) - > p1.price > p2.price ? p1 : p2)
    .ifPresent(System.out: :println);
    What is the result?
  • Question 25

    Given:

    What is the result?