静态导入
外部类:
package com.medivh.learn4;
public class StaticTest
{
public static final int AGE = 3;
public static final String name = "Medivh";
public static void outPut()
{
System.out.println("Test");
}
}
测试类:
package com.medivh.learn3;
import static com.medivh.learn4.StaticTest.AGE;
import static com.medivh.learn4.StaticTest.outPut;;
public class Stest
{
public static void main(String[] args)
{
System.out.println(AGE);
outPut();
}
}
测试结果:
3
Test
静态导入,你可以只导入你需要的变量和方法,并不需要导入整个类;但是会降低程序的可读性。