java - Getting around field shadowing -
for particular program, have abstract superclass several different subclasses. however, i'm having trouble field shadowing illustrated below.
abstract class super { string name; string getname() { return name; } }
now create subclasses each have own "name".
class sub extends super { name = "subclass"; }
however, creating instances of subclass, , calling inherited method getname() yield null due field shadowing.
is there easy way avoid problem, , allow subclasses each have unique field can accessed inherited method?
make field visible in child class , initialize in subclass constructor or in subclass instance initializer.
Comments
Post a Comment