package packA; public class sam1 { public static final double DIAMETER = 12756.32; // kilometers public static void hithere() { System.out.println("Hi There"); } } package packB; import packA.sam1; public class sam2 { public static void main(String args[]) { sam2 objsam2 = new sam2(); objsam2.halfway(); } public void halfway() { sam1.hithere(); System.out.println(sam1.DIAMETER/2.0); } }
-Two Packages – packA and packB – While importing static from packA to packB you should either use import packA.sam1; or import static packA.sam1.*;
Using import static packA.sam1; will not allow to access elements in package
If you use import packA.sam1;
className.StaticVariableName
If you use import static packA.sam1.*;
StaticVariableName