← 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?
- A.Every time an object is created
- B.When the program starts, before main
- C.Once, when the class is first loaded (first used)
- 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 →