I am studying overriding member functions in JAVA and thought about experimenting with overriding member variables.
So, I defined classes
public clas
There is no polymorphism for fields in Java.
Variables
decision happens at a compile time so always Base Class variables (not child’s inherited variables) will be accessed.
So whenever upcasting happens always remember
1) Base Class variables will be accessed.
2) Sub Class methods(overridden methods if overriding happened else inherited methods as it is from parent) will be called.