Java - extends why the super variable a is 0

Viewed 104

Please look at this code:

class Sup {
    int a = 8;

    public void printA() {
        System.out.println(a);
    }

    Sup() {
        printA();
    }
}

public class Sub extends Sup {
    int a = 9;

    @Override
    public void printA() {
        System.out.println(a);
    }

    Sub() {
        printA();
    }

    public static void main(String[] args) {
        Sub sub = new Sub();
    }
}

result: console print: 0 9
I know that subclass will first calls the superclass constructor
but ,why is the 0 9 , not 8 9?

1 Answers
Related