SCJP Certification

Sun Certified Java Programmer Certification exam essentials

August 26th, 2009

Static Import statements

Java Facts, by Daisy Williams.

The static import is a new feature of J2SE 5.0 that allows unqualified access to static members without inheriting from the type containing the static members. It allows you to refer to imported static members as if they were declared in the class that uses them. The class name and a dot (.) are not required to use an imported static member. A static import declaration has two forms – one that imports a particular static member and one that imports all static members of a class.

Static imports are of the following two types:

  1. One in which all the members of a particular static class are imported:
    import static packageName.ClassName.*;
  2. And the other in which only a particular member of a class is imported:
    import static packageName.ClassName.membername;

key points: The syntax of an import statement must be import static followed by the fully qualified name of the static member to be imported.

An asterisk (*) sign must be used at the end of the declaration. The asterisk (*) sign specifies that all static members of the specified class would be available for use within the class declared in the file.

Share

Back Top

Responses to “Static Import statements”

Comments (0) Trackbacks (0) Leave a comment Trackback url
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*