Bird
0
0

Which of the following is TRUE about static blocks in Java?

easy📝 Conceptual Q2 of 15
Java - Static Keyword
Which of the following is TRUE about static blocks in Java?
AThey can access instance variables directly
BThey can only access static variables and methods
CThey can be called explicitly like methods
DThey execute after the main method
Step-by-Step Solution
Solution:
  1. Step 1: Analyze static block access rules

    Static blocks can only access static variables and methods because instance variables are not yet initialized.
  2. Step 2: Understand execution order

    Static blocks execute before the main method, not after.
  3. Final Answer:

    They can only access static variables and methods -> Option B
  4. Quick Check:

    Static block access = static members only [OK]
Quick Trick: Static blocks access only static members, not instance ones [OK]
Common Mistakes:
  • Trying to access instance variables in static blocks
  • Thinking static blocks run after main method
  • Trying to call static blocks explicitly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes