← 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();
}
}
- A.S I C S I C
- B.S I C I C
- C.I C S I C
- 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 →