Java OCA OCP Practice Question 2951

Question

Given:

import java.util.ArrayList;
import java.util.List;

enum Letter {/* w  w w.  j ava  2 s.com*/
   A, B, C
}

public class MyShape {
   public static void main(String[] args) {
      List<String> stuff = new ArrayList<String>();
      stuff.add("Bob");
      stuff.add("Fred");
      new MyShape().go();
   }

   Letter myH = Letter.C;

   void go() {
      for (Letter h : Letter.values())
         if (h == myH)
            System.out.println(myH);
   }
}

Which are true? (Choose all that apply.)

A.   Compilation fails.
B.   main() has-a List
C.   MyShape has-a List
D.   MyShape has-a Letter
E.   The output is  "C"
F.   The output is  "Letter.C"
G.   An exception is thrown at runtime.


D and E are correct.

Note

MyShape has-a Letter named myH.

A, F, and G are incorrect based on the above.

B is incorrect because methods aren't said to "have" classes in the OO "has-a" vernacular (i.e., terminology).

C is incorrect because MyShape's main() "uses" a List, but MyShape doesn't "have" a List.




PreviousNext

Related