mardi 29 janvier 2019

Obtain a field that is inside 2 superclasses

I want to obtain a field that is inside a super class of a class that i'm extending, to undesrstand it better:

class A
{
   private int a = 3; 
}

class B extends A
{

}

class C extends B
{
 // I want to access a value here
}

In C have tried Field a = this.getClass().getSuperclass().getSuperclass().getField("a"); with no sucess

while if in B I put Field a = this.getClass().getSuperclass().getField("a"); i obtain the field.

How it is possible in class C to obtain a?

PD: I am doing this for a unit test





Aucun commentaire:

Enregistrer un commentaire