ProgrammingVery hardInfosys · Accenture

What is printed?

What is printed?
class A {
    static { System.out.print("S"); }
    { System.out.print("I"); }
    A() { System.out.print("C"); }
}
// in main:
new A(); new A();
  1. A. SICSIC
  2. B. ICICS
  3. C. SICIC
  4. D. SCICI

Correct answer: C. SICIC

The static block runs once at class load; each object runs the instance initialiser and then the constructor.

More OOP with C++ and Java questions

Exams that ask this topic