What is the use of static import ?
Answers were Sorted based on User's Feedback
Answer / bijoy baby
if we use static import we can access static methods and
static objects without the reference of class name. But one
disadvantage is u cant know the method or object is from
which class.
| Is This Answer Correct ? | 9 Yes | 2 No |
Answer / 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 |
The static import construct allows unqualified access to
static members without inheriting from the type containing
the static members. Instead, the program imports the
members, either individually:
import static java.lang.Math.PI;
or en masse:
import static java.lang.Math.*;
Once the static members have been imported, they may be used
without qualification:
double r = cos(PI * theta);
The static import declaration is analogous to the normal
import declaration. Where the normal import declaration
imports classes from packages, allowing them to be used
without package qualification, the static import declaration
imports static members from classes, allowing them to be
used without class qualification.
| Is This Answer Correct ? | 2 Yes | 0 No |
Explain the difference between treeset and treemap in java?
What is string length in java?
What are JVM.JRE, J2EE, JNI?
In how many ways we can create threads in java?
To what value is a variable of the Boolean type automatically initialized?
what is an object class?Explain its methods?
Explain when we should make an instance variable private.
without using arthematic operation ,how can you write the logic for adding/substraction/multiplication?
7 Answers Tanla Solutions, Wipro,
What does || mean in vectors?
what is the swingutilities.invokelater(runnable) method for? : Java thread
What is the do while loop syntax?
What is meant by vector class, dictionary class, hash table class, and property class?