Question 6

You want to create a singleton class by using the Singleton design pattern.
Which two statements enforce the singleton nature of the design? (Choose two.)
  • Question 7

    Given:
    class FuelNotAvailException extends Exception { }
    class Vehicle {
    void ride() throws FuelNotAvailException { //line n1
    System.out.println(“Happy Journey!”);
    }
    }
    class SolarVehicle extends Vehicle {
    public void ride () throws Exception { //line n2
    super ride ();
    }
    }
    and the code fragment:
    public static void main (String[] args) throws FuelNotAvailException, Exception
    {
    Vehicle v = new SolarVehicle ();
    v.ride();
    }
    Which modification enables the code fragment to print Happy Journey!?
  • Question 8

    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<Product> products = 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 9

    Given:

    Which two interfaces can you use to create lambda expressions? (Choose two.)
  • Question 10

    Given the code fragment:

    Which modification enables the code to print Price 5 New Price 4?