| 
 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()); 
     } 
   } 
   |