Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Static Import in Java

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 251
    Comment on it

    Static Import

    Static import feature was introduced in Java 5. The functionality provided by static import is it allows a class to access static members of another external class directly without qualifying it with the class name as if it is declared within the called class. Static import reduces code size.

    Program to demonstrate Static import:

    //Java program to demonstrate static import
    
    import static java.lang.System.*;  //Static import for System class 
       
    class StaticImportExample
    {  
      public static void main(String args[])
      {     
        out.println("Hello");//Now no need of System.out  
        out.println("Demo");  
      }   
    }  

    Output:

    Hello

    Demo

    Explanation of above program:

    In above program static members of System class is imported in StaticImportExample class and thus it is able to use it's static member out without qualifying it with the class name System.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: