![]() |
| ||
| Determine instance I am trying to learn some oop in java. What I am trying to do is building a binary tree to convert an ekspresion in reverse police notation to infix notation. The problem is that I have three classes, one abstract called ArithmeticNode which represents a general node, a class called ValueNode representing a leaf with no children and the last class called OperatorNode representing a node with two children. ArithmeticNode abstract class ArithmeticNode ValueNode
OperatorNode class OperatorNode extends ArithmeticNode The problem I am having right now, is how do I know what the children in OperatorNode is an instance of. They can be both an OperatorNode or a ValueNode. Right now I have them as Object which does not work. So the question is: is there a way to decide what instance each child is or do I need to restructure? |
| ||
| Re: Determine instance Check this link on how to determine what kind of class is an instance: http://en.wikibooks.org/wiki/Java_Pr...rds/instanceof |
| All times are GMT -4. The time now is 2:34 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC