Reputation: 661
Consider a package hierarchy folder1/hi
. folder1
contains A.java and hi
contains B.java.
B.java:
package aa.pkg;
public class B { }
A.java:
package hi.aa.pkg;
public class A {B b; }
Now B.java compiles successfully, but A.java does not.
I am using these commands in cmd (if the current directory is folder1
):
javac -d hi hi/B.java
javac -cp hi -d . A.java
It says class B not found.
What is the correct cmd commands to compile A.java or what should the code look like for this to work?
Upvotes: 0
Views: 81
Reputation: 767
You have to import class B into Class A. because both classes are in different packages.
package hi.aa.pkg;
import aa.pkg.B;
public class A {B b; }
Upvotes: 1