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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -