lundi 8 août 2016

Can someone explain the backend functioning of this program, why is default constructor of parent class invoked?

//super class
class parent{int a = 5;}

//sub class
class child extends parent{
    int a = 10;
    void method(){
        System.out.println(a);
    }
}

//main class
class test{
    public static void main(String[] s){
        child c = new child();
        c.method;
    }
}

Aucun commentaire:

Enregistrer un commentaire