Java / Modifiers
How do I print "Hello world" even before main() is executed?
Print the statement inside a static block of code. Static blocks execute 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.
One class can have multiple static blocks and it executes sequentially.
More Related questions...