AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-OOPs: What is static import ?

where and when should we use static import ? explain with sample code.

corejava x 353
OOPs x 49
Posted On : 2013-11-25 20:48:51.0
profile Saksham Kumar - anyforum.in Saksham Kumar
73433936114
up-rate
3
down-rate

Answers


The static import feature of Java 5 facilitate the java programmer to access any static member of a class directly. There is no need to qualify it by the class name.

*****************************  Simple Example of static import  *****************************

import static java.lang.System.*;    
class StaticImportExample{  
 public static void main(String args[]){  
   
  out.println("Hello");//Now no need of System.out  
  out.println("Java");  
 
}  
}  
     
================================  Output  ==================================
Hello
Java
-------------------------------------------------------------------------------------------------------------------------  

**************************  difference between import and static import  **********************

The import allows the java programmer to access classes of a package without package qualification whereas the static import feature allows to access the static members of a class without the class qualification. The import provides accessibility to classes and interface whereas static import provides accessibility to static members of the class.

Posted On : 2013-11-25 21:37:36
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188245674
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in