Java - What is the output: blank final instance variable?

Question

What is the output of the following code?

class Test {
  private final int y; 

  {
    System.out.println("hi");
  }
}
public class Main {

  public static void main(String[] args) {
    new Test(); 
  }
}


Click to view the answer

private final int y; //The blank final field y may not have been initialized

Note

The blank final instance variable y is never initialized.

The compiler would add a default constructor, but it will not initialize y inside the constructor.

Related Quiz