ProgrammingHardInfosys DSE · Wipro Elite

What is printed?

What is printed?
class S {
    static { System.out.print("s"); }
    { System.out.print("i"); }
    S() { System.out.print("c"); }
}
// main: new S(); new S();
  1. A. scici
  2. B. sicic
  3. C. sicsic
  4. D. iscic

Correct answer: B. sicic

The static block runs once at class initialization; each new object runs the instance initializer and then the constructor body.

More OOP with C++ and Java questions

Exams that ask this topic