Home » Interview » Technology

I want to print "Hello" even before main() is executed. How will you acheive that?

Correct 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

← Previous Question Next Question→

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion