I have two classes. One is a public class and the other is an abstract class with HashMap of objects. How do I call the abstract class' HashMap.get(string) method from my public class? I am new to Java and may be having this problem because I am not understanding how to setup my java files correctly.
Here are sections of my two classes...(in same file Evaluator.java)
public class Evaluator {
...code
public int eval (String expr) {
Operator newOpr = (Operator) operators.get(tok);
}
... more code
}
//abstract class
abstract class Operator {
Operator(){
HashMap operators = new HashMap();
operators.put("+",new AdditionOperator());
operators.put("-",new SubtractionOperator());
}
abstract int priority();
static boolean check(String tok){
return true;
}
abstract Operand execute(Operand opd1, Operand opd2);
}
//priority 2, addition and subtraction
class AdditionOperator extends Operator{
@Override
int priority(){
return 2;
}
@Override
public Operand execute (Operand op1, Operand op2){
...code
}
}
Welcome in the java world ! give-us the code of your two Class(the public and the abstract) if you want a preciseanswer.
You probably need to create a not abstract class who extends the abstract Class to call the method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With