There are now two classes with the same name, but the package are different.
Its structure is shown in the following illustration:
The code for two Class A is as follows:
Package pka; public class A {public void PrintA () {System.out.println ("Print:pka. A "); } }
Package PKB; public class A {public void PrintA () {System.out.println ("print:pkb. A "); } }
In addition Main.java for the test class: condition 1:
Call PKA.A in Main
The main code is as follows:
Package pka; public class Main {public static void main (String [] args) {a a=new a (); A.printa ()}}
Test results are:
Situation 2:
When we added a pair of PKB. After the import of a, the situation is different.
The main code is as follows:
Package pka; Import PKB. A public class Main {public static void main (String [] args) {a a=new a (); A.printa ()}}
Test results are:
At this point through a a=new a (), the creation is not in the package of a, but in the import in the pkb of a.
At this point when we want to create an object in the pka, we must use the following methods:
Package pka; Import PKB. A public class Main {public static void main (String [] args) {pka. A a=new pka. A (); A.printa ();//The result is Print:pka. A}}