Is it possible to use inheritance in this situation? (Java)
Posted
by they changed my name
on Stack Overflow
See other posts from Stack Overflow
or by they changed my name
Published on 2010-05-11T03:33:46Z
Indexed on
2010/05/11
3:44 UTC
Read the original article
Hit count: 169
I have ClassA and ClassB, with ClassA being the superclass.
ClassA uses NodeA, ClassB uses NodeB.
First problem: method parameters. ClassB needs NodeB types, but I can't cast from the subclass to the superclass. That means I can't set properties which are unique to NodeB's.
Second problem: When I need to add nodes toClassB, I have to instantiate a new NodeB. But, I can't do this in the superclass, so I'd have to rewrite the insertion to use NodeB.
Is there a way around it or am I gonna have to rewrite the whole thing?
© Stack Overflow or respective owner