0

I am facing some difficulties with this package concept of Java. Let's assume I have the following two directory structures.

dir1
|___com
    |___example
        |___mypackage
            |___myclass.class

dir2
    |___com
        |___example
            |___mypackage
                |___myclass.class

So both the myclass.class files are part of com.example.mypackage. Now if both dir1 and dir2 are on CLASSPATH and I write import com.exaple.mypackage.myclass, which path will be considered?

Ricky
  • 635
  • 2
  • 5
  • 20

1 Answers1

1

So, It is the responsibility of class loader to load classes. So first of all custom classes have been looked up by the JVM then it goes jar files to check the classes. In your case it looks like both are custom classes hence to resolve this issue you have specify which file you want to load then you can add dir1 / dir2 to specify the exact class. JVM picks the latest classes you entered in hierarchy.

Parag Goel
  • 78
  • 8