Answered Questions

  • Predict the output of the given code:

    {geshibot language="java"}public class Test { private static String msg = "HCL "; static{ Thread t = new Thread(new Runnable(){ public void run(){ msg = "Technologies "; } }); t.start(); } public static void main(String[] args){ System.out.print(msg); }}{/geshibot} a) Compiles and prints HCL b) Compiles and prints Technologies c) Compiles and prints HCL Technologies d) Output can be HCL or Technologies


    • Jan 29th, 2015



    • Dec 19th, 2014

    Answer is coming as HCL because there are two threads main and t and both are sharing the common resource ( static variable msg ) . Thread t is getting created and brought into runnable state ( by ca...