What is the use of static import ?

Answers were Sorted based on User's Feedback



What is the use of static import ?..

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

What is the use of static import ?..

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

What is the use of static import ?..

Answer / qamrun nisa

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

What is the use of static import ?..

Answer / mohamed nazar

import static java.lang.Math

Is This Answer Correct ?    1 Yes 8 No

Post New Answer

More Core Java Interview Questions

What is a string what operation can be performed out with the help of a string?

0 Answers  


What is the purpose of stub and skeleton?

0 Answers  


Why we use protected in java?

0 Answers  


what is object slice?

0 Answers  


What is the default size of set in java?

0 Answers  






Under what circumstances an object reference be cast to an interface reference?

3 Answers  


Why hashmap is used in java?

0 Answers  


What are the elements of java?

0 Answers  


Give us a program to check for parenthesis matching using stack.

0 Answers   Genpact,


What is the base class of all classes?

0 Answers  


How are this and super used?

7 Answers   IBM,


What is composition in java?

0 Answers  


Categories