Search code examples
javacannot-find-symboljava-package

'cannot find symbol' compilation error when compiling a class of a package


I created a directory named mypack and added a Java file inside that directory named as A.java . The code for A.java is as follows:

package mypack;

public class A{
    public A(){
        System.out.println("Inside A");
    }
}

And I added another file in the same directory named Demo.java . The code for this file is as follows:

package mypack;

public class Demo {
    public static void main(String args[]) {
        A a = new A();
    }
}

The problem is when I compile the second file Demo.java I get error as such : cannot find symbol A

Unknown symbol A

the directory mypack looks like this :

Directory structure

I don't know why Demo.java the file of the same package (mypack) as that of A.java can't access class A even when I declared it as public in A.java. Please somebody help!!


Solution

  • Maybe you can use

    javac *.java
    

    to complie two java source files at once.