public class Welcome {
public class OperationFactory {
public static Operation createOperate(String operate) {
Operation operation = null;
if("+".equalsIgnoreCase(operate)) {
operation = new OperationAdd();
}else if("-".equalsIgnoreCase(operate)) {
operation = new OperationSub();
}else if("*".equalsIgnoreCase(operate)) {
operation = new OperationMul();
}else {
operation = new OperationDiv();
}
return operation;
}
}
}
The question is that:The method createOperate cannot be declared static; static methods can only be declared in a static or top level type I do not know how to resolve. Thank you
As the error message clearly states, you have 3 options :
createOperate
method to be non-static OperationFactory
class to be static createOperate
to the enclosing Welcome
class
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.