Java Polymorphism
I need some help.Not sure why the compiler is screaming at the following code. Thanks in advance.
publicclass Node{
public Node(){}
publicdouble eval(){
System.out.println("Error: eval Node");
return 0;
}
}
publicclass Binopextends Node{
protected Node lChild, rChild;
public Binop(Node l, Node r){
lChild = l; rChild = r;
}
}
publicclass Plusextends Binop{
public Plus(Node l, Node r){
super(l, r);
}
publicdouble eval(){
return lChild.eval() + rChild.eval();
}
public String toString(){
return"(" + lChild.eval()+"+" + rChild.eval() +")";
}
}
publicclass Constextends Node{
privatedouble value;
public Const(double d){ value = d;}
publicdouble eval(){return value;}
}
This is the test class,once i run it I get the following errors: TestArithmetic.java:4: cannot find symbol
symbol : constructor Plus(Plus,Const,Const)
location: class Plus
Node n = new Plus(
publicclass TestArithmetic{
// evaluate ((3 * 5) + (1 / 4))
publicstaticvoid main(String[] args){
Node n =new Plus(
new Plus(
new Const(3),new Const(5)),
new Const(1),new Const(4));
System.out.println(""+ n.eval());
}
}

