Overriding member variables in Java ( Variable Hiding)

前端 未结 12 972
小蘑菇
小蘑菇 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:40

    As per the Java specifications, the instance variables are not overridden from a super class by a sub class when it is extended.

    Hence the variable in the sub class only can be seen as one sharing the same name.

    Also when the constructor of A is called during the instance creation of B the variable (intVal) is initialized and hence the output.

提交回复
热议问题