Java OCA OCP Practice Question 1974

Question

Given the following class, which of these static initializer blocks can be inserted at (1)?.

public class Main {
  private static int count = 5;
  final static int STEP = 10;
  boolean alive;

  // (1) INSERT STATIC INITIALIZER BLOCK HERE
}

Select the three correct answers.

  • (a) static { alive = true; count = 0; }
  • (b) static { STEP = count; }
  • (c) static { count += STEP; }
  • (d) static ;
  • (e) static {;}
  • (f) static { count = 1; }


(c), (e), and (f)

Note

The static initializer blocks (a) and (b) are not legal since the fields alive and STEP are non-static and final, respectively.

(d) is not a syntactically legal static initializer block.




PreviousNext

Related