using java packagename 2a

Solutions on MaxInterview for using java packagename 2a by the best coders in the world

showing results for - "using java packagename 2a"
Alessio
07 Nov 2016
1//If you use package.* then all the classes and interfaces of this package will be accessible but not subpackages. 
2
3The import keyword is used to make the classes and interface of another package accessible to the current package.
4
5//save by A.java  
6package pack;  
7public class A{  
8  public void msg(){System.out.println("Hello");}  
9}  
10
11//save as B.java
12package mypack;  
13import pack.*;  //Importing the package named pack which contains class A.
14  
15class B{  
16  public static void main(String args[]){  
17   A obj = new A();  
18   obj.msg();  
19  }  
20}