I made two java files in the same directory. // Pac.java - first file package pac; public class Pac{ } // SPac.java - second file package pac; public class SPac{ Pac p; } When I compiled SPac.java, the compiler complained that it couldn't understand the symbol Pac. Then I deleted package statement from both of them and that time Spac.java was compiled fine. Why is that? Please give me some help. Thanks in advance.
Thank for reply, Pho. I put those two files in c:\java\programming\pac directory and set CLASSPATH in autoexec.bat: SET CLASSPATH=.;c:\java\programming\pac; (By the way my os is Win95) Then I rebooted the computer and tried to compile it again. But it didn't work. Is there something wrong with the way to set CLASSPATH or what?
Leave off the actual folder where your package begins, just direct the classpath to the directory where your packages are stored like so: SET CLASSPATH=.;c:\java\programming I'm no classpath expert, but I had this very problem not 2 days ago, and this worked for me.
As far as I'm concerned, that's the best way to learn, mess up, then try again and get it right. That's how I always do it! (Although it may not be the easiest way).