Help the world stop coronavirus! Stay home!

Prev Next

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.

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...

Methods

Comments & Discussions