94
Consider the following Java class declaration:
public class Test {
private final int defaultValue = 10;
private int var;
public Test() {
this(defaultValue); // <-- Compiler error: cannot reference defaultValue before supertype constructor has been called.
}
public Test(int i) {
var = i;
}
}
The code will not compile, with the compiler complaining about the line I've highlighted above. Why is this error happening and what's the best workaround?