Heres a program I wrote which I am having trouble understanding
The output is:
If the runtime type of the object is SubClass in both cases, then why when printing i, does the reference to i resolve to the SuperClass in the first case and the SubClass in the second case. Does the reference variable have some influence as it is different in both cases?
The call to methodX resolves to the SubClass in both cases as I would expect from polymorphism behavior
posted 6 years ago
Welcome to the ranch, Ronan.
Polymorphism only involves instance methods. For everything else (static variables, instance variables, static methods) the only thing that matters is the type of the reference, not the type of the actual object.
All code in my posts, unless a source is explicitly mentioned, is my own.