Cannot reference “X” before supertype constructor has been called, where x is a final variable

前端 未结 6 491
无人及你
无人及你 2020-12-04 11:06

Consider the following Java class declaration:

public class Test {

    private final int defaultValue = 10;
    private int var;

    public Test() {
               


        
6条回答
  •  不思量自难忘°
    2020-12-04 11:54

    constructor is called at the time of object creation so no reference to varable is recognized by compiler as compiler has no knowledge regarding instance variable as object is not created yet.

提交回复
热议问题