What will be the result of attempting to compile and run the following class?
public class Main{ static String s1 = m ("a");{ s1 = m ("b"); }//from ww w. j a v a 2 s. c o m static{ s1 = m ("c"); } public static void main (String args []){ Main it = new Main (); } private static String m (String s){ System.out.println (s); return s; } }
Select 1 option
Correct Option is : B
First, static statements/blocks are called in the order they are defined.
Hence, a and c will be printed.
Next, instance initializer statements/blocks are called in the order they are defined.
Finally, the constructor is called. So, then it prints b.