1.

I Want To Print "hello" Even Before Main Is Executed. How Will You Acheive That?

Answer»

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.

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.



Discussion

No Comment Found