I Want To Print "Hello" Even Before Main() Is Executed. How Will You Acheive That

I Want To Print "Hello" Even Before Main() Is Executed. How Will You Acheive That


  • 16 Dec, 2012

    Siraj Choudhary code will work.

    Comments Received:
    Please give your suggestions and feedback:
  • 7 Jun, 2012

    class Sample
    {

        static String str="Hello";

        static {

            System.out.println(str);

        }

        public static void main(String [] args)
        {
               System.out.println("in main method");
        }
    }

    Comments Received:
    Please give your suggestions and feedback:
  • 29 Dec, 2011

    Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main() method. And it will be executed only once.

    Comments Received:
    Please give your suggestions and feedback:

2009-2016 downloadmela.com. All rights reserved.