Can you please help me understand java8 compiler error on line k3.
public class Color {
private int hue = 10;
public class Shade {
public int hue = 20;
}
public static void main(String[] args) {
System.out.println(new Color().hue); // k1
System.out.println(new Color().new Shade().hue); //k2
System.out.println(new Shade().hue); //k3
}
}
Above code compiles if I comment out k3. k1 outputs 10, k2 outputs 20.
With k3, compilation fails saying:
Color.java:11: error: non-static variable this cannot be referenced from a static context
System.out.println(new Shade().hue);
Main method is under static context,understood. Where is non-static 'this' variable in this picture. Thanks.