Question: What will be the result of compiling and running the following program? Select the one correct answer. (a) The code will fail to compile, because

What will be the result of compiling and running the following program?

public class MyClass { public static void main (String [] args) {

Select the one correct answer.

(a) The code will fail to compile, because of the instance initializer block.

(b) The code will fail to compile, because of the static initializer block.

(c) The code will compile, and print 50, 70, 0, 20, 0 at runtime.

(d) The code will compile, and print 50, 70, 0, 20, 20 at runtime.

(e) The code will compile, and print 5, 70, 0, 20, 0 at runtime.

(f) The code will compile, and print 5, 70, 0, 20, 20 at runtime.
(g) The code will compile, and print 5, 7, 0, 20, 0 at runtime.
(h) The code will compile, and print 5, 7, 0, 20, 20 at runtime.

public class MyClass { public static void main (String [] args) { MyClass obj = new MyClass (n); } } static int i = 5; static int n; int j = 7; int k; public MyClass(int m) { System.out.println (i + ", } = 70; n = 20; // Instance initializer block static (i = 50; } // Static initializer block +n +", " + m);

Step by Step Solution

3.39 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

c The program will compile and print 50 70 0 20 0 at runtime All fields are given def... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming 8th Questions!