static import – JAVA

static import is used to make the availability of static members of the class in our current source file(.java).

Simply when we use import statement then it makes availability of the particular class which is defined in the import statement.

Static members of a class are not imported by the simple import statement.

Whereas static import is used to make availability of the all static methods or one particular method of the related class.

Program:

//program to show concept of static import

import static java.lang.Math.*;

class StaticImportDemo

{

public static void main(String ar[])

{

double theta=45.0;

double radians = Math.toRadians(theta);

System.out.println(radians);

double res=cos(PI*theta);

System.out.println(“cos+theta=”+res);

}

}

Leave a Reply

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