posted 22 years ago
Data members can be hidden in subclasses, while methods can be overridden in subclasses. Deciding which method to call is determined at runtime, while de decision which data member must be read/altered, is decided at compile time by the compiler itself.
While you didn't explicitly constructed a Super object, it was created though, being a part of the Sub object, because a Sub object inherits from its parent class Super.
Your Sub object contains four data members, a and b from the Superclass and a and c defined in the Sub class itself. The first member 'a' is hidden by the latter member 'a'.
If you assign a Sub object to a Super variable, and later refer to member a, the compiler decides that you're refering to member a of the Super class. If you'd tried to refer to member 'c' using the Super variable, the compiler would have complained, because a Super object doesn't contain a member named 'c'. Just for the fun of it, change your classes like this:
kind regards