/*
* 靜態(tài)導(dǎo)入:
* 格式:import static 包名….類名.方法名;
* 可以直接導(dǎo)入到方法的級(jí)別
*
* 靜態(tài)導(dǎo)入的注意事項(xiàng):
* A:方法必須是靜態(tài)的
* B:如果有多個(gè)同名的靜態(tài)方法,容易不知道使用誰(shuí)?這個(gè)時(shí)候要使用,必須加前綴。由此可見,意義不大,所以一般不用,但是要能看懂。
*/
import static java.lang.Math.abs;
import static java.lang.Math.pow;
import static java.lang.Math.max;
//錯(cuò)誤
//import static java.util.ArrayList.add;
public class StaticImportDemo {
public static void main(String[] args) {
// System.out.println(java.lang.Math.abs(-100));
// System.out.println(java.lang.Math.pow(2, 3));
// System.out.println(java.lang.Math.max(20, 30));
// 太復(fù)雜,我們就引入到import
// System.out.println(Math.abs(-100));
// System.out.println(Math.pow(2, 3));
// System.out.println(Math.max(20, 30));
// 太復(fù)雜,有更簡(jiǎn)單
// System.out.println(abs(-100));
System.out.println(java.lang.Math.abs(-100));
System.out.println(pow(2, 3));
System.out.println(max(20, 30));
}
public static void abs(String s){
System.out.println(s);
}
}
聯(lián)系客服