Static Imports


o    Static imports allow static classes to be  imported.

import static java.lang.System.out;

public class StaticImportTest

{

public static void main(String[] args)

{

out.println(“Hello, world!”);

}

}

o    Static imports also allow the import of static methods and variables.

import static java.util.Arrays.sort; //import sort method

import static java.lang.Math.*; //import static members

public class StaticImportTest {

public static void main(String[] args) {

int[] numbers = {3, 6, 1, 4, 5, 2};

sort(numbers); //sort is method in Arrays class

double d = abs(-15); //abs is method in Math class

}

}

About mayurmevada
I am a software professional with having helping nature...

Leave a comment