Java OCA OCP Practice Question 3256

Question

What will be the result of executing the following program code with assertions enabled?

import java.util.LinkedList;

public class Main {
  public static void main(String[] args) {
    LinkedList<String> lla = new LinkedList<String>();
    LinkedList<String> llb = new LinkedList<String>();
    assert lla.size() == llb.size() : "empty";

    lla.add("Hello");
    assert lla.size() == 1 : "size";

    llb.add("Hello");
    assert llb.contains("Hello") : "contains";
    assert lla.get(0).equals(llb.get(0)) : "element";
    assert lla.equals(llb) : "collection";
  }//from w w w. ja  v  a 2s. c  o m
}

Select the one correct answer.

  • (a) Execution proceeds normally and produces no output.
  • (b) An AssertionError with the message "size" is thrown.
  • (c) An AssertionError with the message "empty" is thrown.
  • (d) An AssertionError with the message "element" is thrown
  • (e) An IndexOutOfBoundsException is thrown.
  • (f) An AssertionError with the message "container" is thrown.


(a)

Note

Execution proceeds normally and produces no output. All assertions are true.




PreviousNext

Related