Java OCA OCP Practice Question 1028

Question

What is the output of the following program?

public class Main {
   static int i = 1, j = 2;
   static {/*from www  .  j a  va2  s  . c  om*/
      display(i);
   }

   public static void main(String[] args) {
      display(j);
   }

   static void display(int n) {
      System.out.print(n);
   }

}
  • A. 1
  • B. 2
  • C. 12
  • D. 21


C.

Note

The static initializer is executed followed by main().




PreviousNext

Related