WHAT IS STATIC IMPORT IN JAVA

 /*  
 static import allow us to call static methods with out using class name.  
 This program will show you how to do that.   
 */  
 import static java.lang.Math.*; // static import   
 class ImportStaticTest  
 {  
      public static void main(String[]args)  
      {  
           double a = cos(0); // calling Math.cos() function.   
      /*  
           Generally we call this function. like   
           a = Math.cos(0);   
      */  
           System.out.println("COS(0) = "+a);  
      }  
 }  

Post a Comment

1 Comments

  1. Though it reduces amount of code we need to write it looks to me some what confusing because it hides the fact that cos() method is from Math class and it appears like its from this class.

    Javin
    How classpath works in Java

    ReplyDelete