java - How to reference a shadowed variable in the superclass of a superclass? -


this simple example of inheritance there shadowed variable x.

class a{     int x=1; } class b extends a{     int x=2; } class c extends b{     int x=3;     int y; } 

how can reference shadowed variable x of class in class c?(i want y=super.super.x; works well.)

not hard might think. (while encourage avoiding situation,) if have class c inherits class b, in turn inherits class a, of implement public field x, using super wrong way go it.

instead, given class c, try this:

((a)this).x;   //don't forget parentheses! 

that give value of x a. also,

super.x == ((b)this).x; 

which why, single steps, use super.

hopefully helps.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -