Path: csiph.com!aioe.org!.POSTED!not-for-mail From: parmenides Newsgroups: comp.lang.java.programmer Subject: Is it necessary the source file should be at the same location with the class file? Date: Sun, 24 Jul 2016 00:55:20 +0800 Organization: Aioe.org NNTP Server Lines: 74 Message-ID: NNTP-Posting-Host: KKephej3o10WsolWfXEGyA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 X-Notice: Filtered by postfilter v. 0.8.2 X-Mozilla-News-Host: news://nntp.aioe.org:119 Xref: csiph.com comp.lang.java.programmer:35110 Hi, I try to understand the relationship of the souce file and the class file. I have the following file cascade: work/Test.java work/Circle.java work/compute/shape/ The Test.java is written: import compte.shape.*; public class Test { public static void main(String[] args) { Circle c = new Circle(3); System.out.println(c.circleArea()); } } The Circle.java is written: package compute.shape; public class Circle{ double radius; public Circle(double radius){ this.radius = radius; } public double circleArea() { return Math.PI*radius*radius; } } I compiled the Circle.java and copied the Circle.class to the compute/shape directory: javac Circle.java cp Circle.class compute/shape Then, I compiled the Test.java: javac Test.java I got a message like this: Test.java:5: error: cannot access Circle Circle c = new Circle(); I modified the first line of Test.java as follows: import compte.shape.*; ===> import compte.shape.Circle; I compiled the Test.java again: javac Test.java and it is all right. Then, I moved the Circle.java to compute/shape directory mv Circle.java compute/shape and changed the Test.java back: import compte.shape.Circle; ===> import compte.shape.*; At last, the compiling of the Test.java is correct. It seems that the source file should be at the same location as the class file.Is this right? Why the compiling is wrong? Thanks.