Java OCA OCP Practice Question 3000

Question

Given:

class Shape {
   int getArea() {
      return 24;/* ww  w.  j  ava  2 s  .  c o m*/
   }
}

public class Main extends Shape {
   enum Letter {
      A, B, C
   };

   public static void main(String[] args) {
      Letter v = Letter.B;
      switch (v) {
      case A:
         System.out.print("12 ");
      default:
         System.out.print(getArea() + " ");
      case C:
         System.out.print("110 ");
      }
   }
}

What is the result? (Choose all that apply.)

  • A. 24
  • B. 24 110
  • C. 24 110 12
  • D. Compilation fails due to a misuse of enums
  • E. Compilation fails due to a non-enum issue.


E is correct.

Note

The code fails because the instance method getArea() is called from a static method.

The enums are used correctly.

If getArea() was a static method, the output would be "24 110".




PreviousNext

Related