Gihan Madushanka wrote:Therefore I presume the problem must be with the package names or directories.
Yes, that's the problem. Your directory structure must match your package structure. So class
Fruit must be in a directory named
food, because it is in a package named
food.
With the code as you have it above, with
Apple and
Test in the default package (you don't have a
package statement in those source files), it should look like this:
C:\MyProject
|
+-- Apple.java
|
+-- Test.java
|
+-- food
|
+-- Fruit.java
Compile it with:
C:\MyProject> javac food\Fruit.java
C:\MyProject> javac Apple.java
C:\MyProject> javac Test.java
See:
Lesson: Packages in Oracle's Java Tutorials.