What is the use of static import ?

Answer Posted / praveen kumar

The normal import declaration imports classes from packages, so that they can be used without package reference. Similarly the static import declaration imports static members from classes and allowing them to be used without class reference.

Now, we have got an excellent java feature from java 1.5. Ok now we shall see how we can abuse this!

Can i static import everything?
like, import static java.lang.Math.*; – yes it is allowed! Similarly you do for class import.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we execute java program without main method?

524


Explain the difference between protected and default access.

520


Are static members inherited to sub classes?

644


Explain JMS in detail.

620


How do you override a method?

555






What is the purpose of checked and unchecked exceptions in JAVA?

571


What is the syntax and characteristics of a lambda expression?

563


If a method is declared as protected, where may the method be accessed?

538


How can we create a thread in java?

591


How to make a read-only class in java?

597


Can we write any code after throw statement?

615


What is compareto () in java?

544


What is the java idl system?

587


What is the meaning of course?

589


Can you access non static variable in static context?

561