Accessing indirect super class variable that has been hidden in a third extended class

后端 未结 1 818
广开言路
广开言路 2021-01-27 03:50

Suppose i have a code as below :

    class A {
    int a = 1; 
    }

    class B extends A {
    int a = 2; 
    }

    class C extends B {
    int a = 3;

             


        
相关标签:
1条回答
  • 2021-01-27 04:39

    Cast to A and then access the variable:

    ((A)this).a
    
    0 讨论(0)
提交回复
热议问题