Java - What is the output: this keyword vs static?

Question

What is the output of the following code?


public class Main {
  static int varU = 555;
  static int varV = varU;
  static int varW = this.varU; 

  public static void main(String[] args) {
     System.out.println(varU);
  }
}


Click to view the answer

static int varW = this.varU; // A compile-time error

Note

The keyword this is illegal in the context of a class.

You cannot use it when you initialize a class variable.

Related Quiz