Java OCA OCP Practice Question 2674

Question

Given:

import java.util.LinkedList;
import java.util.List;

public class Main {
   public static void main(String[] args) {
      List<Integer> i = new LinkedList<Integer>();
      i.add(4);/*from w w w.ja v a2 s  .c om*/
      i.add(2);
      i.add(5);
      int r = 1;
      doStuff(r);
      System.out.println(i.get(r));
   }

   static int doStuff(int x) {
      return ++x;
   }
}

What is the result?

  • A. 2
  • B. 4
  • C. 5
  • D. Compilation fails.
  • E. An exception is thrown at runtime.


D is correct.

Note

Of course, you need to import some stuff for this program to compile.

This is an easy question if you spot the problem.

If you don't, it'll seem tricky, so watch out for these on the real exam.

With the proper import statements in place, A would be correct.




PreviousNext

Related