Question 131

Given the code fragment:
List<Double> doubles = Arrays.asList (100.12, 200.32);
DoubleFunction funD = d -> d + 100.0;
doubles.stream (). forEach (funD); // line n1
doubles.stream(). forEach(e -> System.out.println(e)); // line n2
What is the result?
  • Question 132

    Given:
    class UserException extends Exception { }
    class AgeOutOfLimitException extends UserException { }
    and the code fragment:
    class App {
    public void doRegister(String name, int age)
    throws UserException, AgeOutOfLimitException {
    if (name.length () < 6) {
    throw new UserException ();
    } else if (age >= 60) {
    throw new AgeOutOfLimitException ();
    } else {
    System.out.println(“User is registered.”);
    }
    }
    public static void main(String[ ] args) throws UserException {
    App t = new App ();
    t.doRegister(“Mathew”, 60);
    }
    }
    What is the result?
    User is registered.
  • Question 133

    Given the code fragment:

    What is the result?
  • Question 134

    Given the code fragment:

    You have been asked to define the ProductCode class. The definition of the ProductCode class must allow c1 instantiation to succeed and cause a compilation error on c2 instantiation.
    Which definition of ProductCode meets the requirement?
  • Question 135

    Given the code fragment:

    Which code fragment, when inserted at line 9, enables the code to print true?