Overriding member variables in Java ( Variable Hiding)

前端 未结 12 1234
小蘑菇
小蘑菇 2020-11-22 03:07

I am studying overriding member functions in JAVA and thought about experimenting with overriding member variables.

So, I defined classes

public clas         


        
12条回答
  •  生来不讨喜
    2020-11-22 03:44

    Well, I hope u got the answer. If not, you can try seeing in the debug mode. the subclass B has access to both the intVal. They are not polymorphic hence they are not overriden.

    If you use B's reference you will get B's intVal. If you use A's reference , you will get A's intVal. It's that simple.

提交回复
热议问题