🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: static, final and Nested Classes: all 10 questions

Quiz: static, final and Nested Classes · Question 2 of 10

When does a static block run?

When does a static block run?

  1. A.Every time an object is created
  2. B.When the program starts, before main
  3. C.Once, when the class is first loaded (first used)
  4. D.Only when a static method is called by name
Answer & explanation

Correct answer: Once, when the class is first loaded (first used)

The JVM loads a class lazily, when it is first used, and runs its static blocks once at that time.

Can you get the rest right without peeking?

Take the timed Quiz: static, final and Nested Classes quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →