This can happen when beginners run the package file for the first time without the IDE.
This is caused by not placing the file correctly.
The first thing to know is that classes aandB are independent of each other, not with the Exam class.
Then, the program can run, call each other, the most important is not the suffix . Java files, but the suffix name is a . class file.
To illustrate the relationship between the classes, I used a graph to indicate:
Because of the relationship on the diagram, you need a packaged statement in class a :
Package pkg1;
There is also a need to have a packaging statement in class B:
Package pkg1.pkg2;
And it needs to be placed at the front of the code.
The last invocation of class aandB is the exam3_24 class, so There should be access package statements in the Exam3_24 class:
Import Pkg1. A;import pkg1.pkg2.b;
To compile:
Generated two suffixes named . Class files, which is what we want.
But the placement is not correct and should be placed separately (the location I am currently compiling is d:\):
The pkg1,pkg2 folder in the diagram is created by itself.
Compile the exam3_24 class right now, and run with the result:
Java (self-write) package does not exist problem resolution