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...

  • What will be the result of compiling and executing the code listed below?

    {geshibot language="java"} public class Finder { public static void main(String[] args){ System.out.println(X.Y.Z); }} class X{ static class Y{ static String Z ="Apple"; } static W Y = new W(); } class W{ String Z = "Orange";}{/geshibot} a) Apple b) Orange c) Compile time Error d) Runtime Exception is thrown


    • Jun 28th, 2016

    B) Orange

    Abhinav Rohatgi

    • Apr 1st, 2013