I am trying to create two classes A and B that exist within a named package named components. A is a public class Window and B is a public class Door which contains an instance of A. The issue is that when compiling B using
javac -classpath . Door.java
, B cannot find A.
I understand that I can make this code work in an unnamed default package with no import clauses however I want these files to exist within one named class so that they can be imported elsewhere.
I have demonstrated to myself that Door.java will compile if the package components; line is commented out from both files however I do want to have this as a package named components.
I have also tried using import components.Window; within B but this doesn't work either.
//class A
package components;
public class Window{
public void rollup(){}
public void rolldown(){}
}
//class B
package components;
public class Door{
public Window window = new Window();
public void open(){}
public void close(){}
}
My current code shows this which demonstrates that package B currently cannot access package A.
Door.java:8: error: cannot find symbol
Window window = new Window();
^
How do I fix this code to allow B to create an instance of A whilst being within the same named package?
Window.java?javac -sourcepath . components/Door.javain the parent of the folder that contains both classes. For example, if you have Project/components/Door.java, you have to run the command from the folder Project.