Question 11

Given the code fragments:

What is the result?
  • Question 12

    Given:

    Your design requires that:
    - fuelLevel of Engine must be greater than zero when the start() method is invoked.
    - The code must terminate if fuelLevel of Engine is less than or equal to zero.
    Which code fragment should be added at line n1 to express this invariant condition?
  • Question 13

    Given the code fragment:

    Which code fragment, when inserted at line 7, enables printing 100?
  • Question 14

    Given the code fragment:
    public static void main (String[] args) throws IOException {
    BufferedReader brCopy = null;
    try (BufferedReader br = new BufferedReader (new FileReader("employee.txt"))) { //
    line n1
    br.lines().forEach(c -> System.out.println(c));
    brCopy = br;//line n2
    }
    brCopy.ready(); //line n3;
    }
    Assume that the ready method of the BufferedReader, when called on a closed BufferedReader, throws an
    exception, and employee.txt is accessible and contains valid text.
    What is the result?
  • Question 15

    Given:

    and the code fragment:

    What is the result?