ProgrammingVery hardTCS NQT Prime · Infosys SP

What is printed?

What is printed?
class A {
    int a = f("a");
    { f("i"); }
    A() { f("c"); }
    int f(String s) { System.out.print(s); return 1; }
    int b = f("b");
}
// main: new A();
  1. A. aibc
  2. B. abic
  3. C. cabi
  4. D. iabc

Correct answer: A. aibc

Field initializers and instance initializer blocks run in textual order (a, i, b) before the constructor body (c).

More OOP with C++ and Java questions

Exams that ask this topic