using java fully qualified name

Solutions on MaxInterview for using java fully qualified name by the best coders in the world

showing results for - "using java fully qualified name"
Joaquín
07 Aug 2019
1//If you use fully qualified name then only declared class of this package will be accessible. Now there is no need to import. But you need to use fully qualified name every time when you are accessing the class or interface.
2
3It is generally used when two packages have same class name e.g. java.util and java.sql packages contain Date class.
4
5//save by A.java  
6package pack;  
7public class A{  
8  public void msg(){System.out.println("Hello");}  
9}  
10
11//save by B.java  
12package mypack;  
13class B{  
14  public static void main(String args[]){  
15   pack.A obj = new pack.A(); // using fully qualified name  
16   obj.msg();  
17  }  
18}