How to use a method from java.lang.Math
class if I imported static methods. I know I can just write Math.abs(-12), but are there other ways to do this?
import static java.lang.Math.*;
public class Lesson1 {
private static int abs(int x) {
System.out.println("My abs method");
return x;
}
public static void main(String[] args) {
System.out.println(abs(-12));
}
}
If you want to use your custom method abs
, call it with Lesson1.abs(-12)
. If you want to use java.lang.Math.abs
call it with Math.abs(-12)
or directly abs(-12)
cause the static import.
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.