← Quiz: Object Initialization Order: all 10 questions
Quiz: Object Initialization Order · Question 1 of 10
What does this print? (code)
What does this print?
class A {
static StringBuilder log = new StringBuilder();
static { log.append("S"); }
{ log.append("I"); }
A() { log.append("C"); }
}
public class Main {
public static void main(String[] args) {
new A();
new A();
System.out.println(A.log);
}
}
- A.SICSIC
- B.SICIC
- C.ICSIC
- D.SCICI
Answer & explanation
Correct answer: SICIC
The static block runs once; each object runs the instance block, then the constructor.
Can you get the rest right without peeking?
Take the timed Quiz: Object Initialization Order quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →