Re: an inheritance question
Lew wrote:
Would you provide an SSCCE? The code you provided is completely
insufficient to provide any hint as to what your trouble is. For one
thing, '_person' (which by convention should be spelled without
underscores) is not declared.
www wrote:
Sorry. I left out "Parent". They should be:
public Base {
protected Parent _person;
...
}
public Sub extends Base {
_person = new ChildA();
_person.doA(); //WRONG !!!! error message: doA() is unresolved
}
This still isn't an SSCCE, and you still haven't provided the error message,
but I see your problem. '_person' (lose the underscore) is of type Person,
which, presumably since you haven't provided an SSCCE, does not have a doA()
method. You cannot call a method not defined for the type of the variable.
Follow Tom's and Patricia's advice. Lose the protected instance variable and
step back from the problem for a broader picture.
Quite often, the process of preparing an SSCCE reveals the answer to your
problem before you even ask for help, and it makes obtaining answers when you
do ask so much more efficient.
First hit off Google for "SSCCE":
<http://mindprod.com/jgloss/sscce.html>
or you can view
<http://www.physci.org/codes/sscce.html>
--
Lew