problem description
in the process of learning java static import, the myMath class and static_import class are written in the same folder . The static_import class invokes the static methods of the myMath class directly by statically importing the myMath class.
myMath.java
public class myMath{
public static int div(int x, int y) throws Exception{
System.out.println("===start===");
int result = 0;
try{
result = x / y;
}catch(Exception e){
throw e;
}finally{
System.out.println("===end===");
}
return result;
}
public static int add(int x, int y){
return x + y;
}
}
static_import.java
import static myMath.*;
public class static_import{
public static void main(String args[]){
System.out.println("Add operation:" + add(10,20));
try{
System.out.println("divide operation: " + div(10,2));
}catch(Exception e){
e.printStackTrace();
}
}
}
the error prompt is shown in the following figure:
how do I use import static to import the static methods of the myMath class into the static_import class when the myMath.java and static_import classes to be imported are in the same folder?