Sunday, 29 January 2012

Is static import automatic for java.lang package ?

java.lang package is imported automatically  in every java program but are static members of classes belong to the package java.lang is automatic ?
No, static import is not automatic and programmer has to provide explicit class and its member name in import statement.
e.g. 
public class JavaImportTest
{
public static void main(String ar[])
{
out.println("Hello");//compile time error , cannot be resolved
}

}   


import static java.lang.System.out;

public class JavaImportTest
{
public static void main(String ar[])
{
out.println("Hello");//compile and print Hello
}
}

No comments:

Post a Comment