Posted on 2009-07-20 07:18
London2012 阅读(145)
评论(0) 编辑 收藏 所属分类:
J2SE
package staticEx;
public class TranscendentalConstants {
public static final double PI = 3.14159;
public static final double E = 2.71828;
}
public class IrrationalConstants {
public static final double SQRT_TWO = 1.414;
public static final double SQRT_THREE = 1.732;
}
//在类中导入静态变量和方法
package staticEx;
import static staticEx.IrrationalConstants.SQRT_TWO;
import static staticEx.IrrationalConstants.SQRT_THREE;
import static staticEx.TranscendentalConstants.PI;
public class ConstantsWithStaticImport {
public static double sinPiOverFour() {
return SQRT_TWO / 2;
}
public static void main(String[] args) {
System.out.println("Pi is approximately " + PI);
System.out.println("The sin of Pi/4 is about " +
sinPiOverFour());
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/qiuchun/archive/2004/10/09/129502.aspx