🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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);
    }
}
  1. A.SICSIC
  2. B.SICIC
  3. C.ICSIC
  4. 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 →