🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: static, final and Nested Classes: all 10 questions

Quiz: static, final and Nested Classes · Question 1 of 10

What does this print? (code)

What does this print?

class A {
    static { System.out.print("S "); }
    { System.out.print("I "); }
    A() { System.out.print("C "); }
}
public class Main {
    public static void main(String[] args) {
        new A();
        new A();
    }
}
  1. A.S I C S I C
  2. B.S I C I C
  3. C.I C S I C
  4. D.S C I C I
Answer & explanation

Correct answer: S I C I C

The static block runs once when A is loaded. Each object then runs the instance block and the constructor.

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 →