The static import statement

By using the static import statement, the developer gain access to the constants and static methods of the imported class. It is possible to import an individual static member of a class or all its static members.

The syntax is :

import static package_name.ClassName.classMember;

The * placeholder can also be used to access all static members of a class :

import static package_name.ClassName.*;

NOTE : The order of the keywords import and static can’t be reversed. This will lead in a compilation error.

 

Add a Comment

Your email address will not be published.