Java variable definition error 3

Question

What is the output of the following code?

public class Main {
  public static void main(String[] args) {
    int x;
    System.out.println(x);
  }
}


Compile time error
The local variable x may not have been initialized

Note

Using the value of a local variable before it's initialized will trigger a compilation error.

All local variables must be initialized before their values can be used in expressions.




PreviousNext

Related