What are the types of static import?

Static import is a new feature introduced in j2SE 5.0. It allows the static members of the imported class to be treated as if they were declared in the class that uses them. It is now no longer required to use the static class name and dot operator as was required before. 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;
  • Share/Bookmark

Static Import statements

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.

  • Share/Bookmark