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


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) {

Click to view the answer

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


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

You cannot use it when you initialize a class variable.

Related Quiz