Java Field Hiding

后端 未结 3 545
长发绾君心
长发绾君心 2020-12-10 19:57

I was wondering what it means to say a field is hidden between 2 java classes and what it means when running code in terms of resulting output?

I have an abstract c

3条回答
  •  無奈伤痛
    2020-12-10 20:14

    what would be the value of the boolean field in the superclass and the boolean field in the subclass?

    The value of field variable in superclass will remain false and the value of field in the subclass will remain true.

    Does subclass field stay as FALSE after the assignment above?

    No. You cannot override static variables in Java. What essentially happens is the definition in the sub class hides the variable declared in the super class.

    For a nice example and explanation, see SO Question

    I also suggest you try it out yourself to see what happens.

提交回复
热议问题