Engineering Full Stack Apps with Java and JavaScript
What will be the result of attempting to compile and run the following code?
public class InitClass{ public static void main(String args[ ] ){ InitClass obj = new InitClass(5); } int m; static int i1 = 5; static int i2 ; int j = 100; int x; public InitClass(int m){ System.out.println(i1 + " " + i2 + " " + x + " " + j + " " + m); } { j = 30; i2 = 40; } // Instance Initializer static { i1++; } // Static Initializer }
Select 1 option
A. The code will fail to compile, since the instance initializer tries to assign a value to a static member.
B. The code will fail to compile, since the member variable x will be uninitialized when it is used.
C. The code will compile without error and will print 6, 40, 0, 30, 5 when run.
D. The code will compile without error and will print 5, 0, 0, 100, 5 when run.
E. The code will compile without error and will print 5, 40, 0, 30, 0 when run.