1Z0-830 practice question 7 of 25
Which of the following statements is TRUE about static initializers in Java?
Full set: 116 questionsBoth A and D are factually correct statements. Static initializers are blocks of code used to initialize a class's static fields. This initialization occurs when the class is first loaded and initialized by the JVM. Because class initialization must happen before any instance of that class can be created, static initializers are guaranteed to execute before any instance initializers or constructors are run. Therefore, they are used to initialize static fields (D) and they are always executed before instance initializers (A).
B. Static initializers execute in a static context and cannot access non-static instance variables directly.
C. Static initializers do not have access modifiers; they are declared with the static keyword followed by a code block.
1. Gosling
J.
Joy
B.
Steele
G.
& Bracha
G. (2021). The Java® Language Specification
Java SE 17 Edition. Oracle America
Inc. Section 8.7
"Static Initializers" and Section 12.4.2
"Detailed Initialization Procedure".
2. Oracle. (2022). The Java™ Tutorials: Initializing Fields. Oracle Help Center. The section "Static Initialization Blocks" explains their purpose and execution time.
3. Flanagan
D. (2014). Java in a Nutshell (6th ed.). O'Reilly Media. Chapter 3
"Object-Oriented Programming in Java"
Section "Static Members and Static Initializers".
Keep practicing
Take the free 1Z0-830 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other 1Z0-830 practice questions
- Question 1A consumer needs to access a service provided by another module. Which of the following s…
- Question 2Which of the following statements is TRUE about modules in Java SE 21?
- Question 3What interface does a class need to implement to be eligible for serialization?
- Question 4What is the primary benefit of encapsulation in Java?
- Question 5A Path object represents which of the following?
- Question 6Which of the following statements about overloaded methods with varargs is TRUE?
