Java OCA OCP Practice Question 1869

Question

Which declaration can be inserted at (1) without causing a compilation error?.

interface MyConstants {
  int r = 42;
  int s = 69;
  // (1) INSERT CODE HERE
}

Select the two correct answers.

  • (a) final double circumference = 2 * Math.PI * r;
  • (b) int total = total + r + s;
  • (c) int AREA = r * s;
  • (d) public static MAIN = 15;
  • (e) protected int CODE = 31337;


(a) and (c)

Note

Declaration (b) fails, since it contains an illegal forward reference to its own named constant.

The field type is missing in declaration (d).

Declaration (e) tries illegally to use the protected modifier, even though named constants always have public accessibility.

Such constants are implicitly public, static, and final.




PreviousNext

Related