Now when ever i remove the "Class1.java" from the MyDir ---- there is no error. & successful compilation,running.
when ever i place the "Class1.java" in the MyDir ---- error appears......... what is the reason for this ?
In short, when you use "import p1.*", the compiler looks for the "Class1" and find it the current dir. In order to explicitly tell the compiler to look for the dir "p1" either you have to use the full reference, like "p1.Class1" OR mention it on CP. But when you delete the java file then it looks for the "p1" dir.
Moguluri, the problem lies in the way your source files are located. When I put Class1.java inside folder p1, then run "javac Class2.java", I get no errors. If I move Class1.java to the root folder and remove folder p1 I also get an error. Try always using the package structure for your source files as well.