What is the output of the following program?
public class Main { static int i = 1; static {//from w w w. j a v a 2 s .c o m ++i; } public static void main(String[] args) { increment(i, 5); display(i); } static void increment(int n, int m) { n += m; } static void display(int n) { System.out.print(n); } static { ++i; } }
B.
Both static initializers are executed before main()
is executed.
The increment()
method has no effect on the value of i.