Java OCA OCP Practice Question 636

Question

Given the following class, which of the given blocks can be inserted at line 1 without errors?

public class Main{ 
       private static int loop = 15 ; 
       static final int my = 10 ; 
       boolean flag ; 
       //line 1 
} 

Select 4 options

  • A. static {System .out.println ("Static"); }
  • B. static { loop = 1; }
  • C. static { loop += my; }
  • D. static { my = 10; }
  • E. { flag = true; loop = 0; }


Correct Options are  : A B C E

Note

my is final and so it can never be changed after it is given a value.

For Option E., flag is not static and so it can be accessed only from a non-static block.

loop is static so can be accessed from any block.




PreviousNext

Related