This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on Static import!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on Static import!!" Watch "Question on Static import!!" New topic
Author

Question on Static import!!

Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

static imports:
===============



Krishna Srinivasan
Spring Tutorials, OCAJP Mock Questions, 400+ OCPJP Mock Questions
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Nice question. Brett's Devloper notes has a good explanation

1 is the answer The same question could be extended to static methods.


Groovy
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

Surprising Static Imports
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

few tips on static import:

Two types of static import declarations:

1)single-type import declaration.
example:
import static Enum.EnumMember.Java;
2)static import on demand.
example:
import static Enum.EnumMember.*;


On-demand-static import never shadow the previous imports declarations.
example:
import static Enum.EnumMember.Java;
import static Enum1.EnumMember.*;

In the above example both the enum type has the variable Java.When we are usiing
the on-demand-static-import(import static Enum.EnumMember1.* .It will not shadow
the previous declaration import static Enum.EnumMember.Java;

But two single-type static imports trying to import the same variable, the compile
time error occurs.

example:
import static Enum.EnumMember.Java;
import static Enum1.EnumMember.Java;
 
wood burning stoves
 
subject: Question on Static import!!