What is the output of the following code?
class Test { private final int y; { y = 10; System.out.println("1"); } { y = 10; System.out.println("2"); } { System.out.println("hi"); } } public class Main { public static void main(String[] args) { new Test(); } }
{ y = 10; //The final field y may already have been assigned System.out.println("2"); }
The code would not compile because it initializes y more than once inside two instance initializers: