Question

I know this is a basic question. I've been working with Java for a long time... However today I suddenly thought about creating a package without an IDE. So I thought the following should have worked :

package test;

class Node {

    int data;
    Node left, right;

    public Node(int data) {
        this.data = data;
        this.left = left;
        this.right = right;
    }
}

class SumBinaryTree {

    public static void main(String[] args) {
        ////
    }
}

Now, I thought that now package test contained class Node and class SumBinaryTree. After doing javac SumBinaryTree.java, I wrote the following code :

package test;

class Test {
    public static void main(String[] args) {
        Node t = new Node(0);
    }    
}

Now, since package test; is present, I thought this would work. However, on doing javac Test.java, I got an error with the two Node lines. I then realized that I did not know what was correctly going on and could use some help understanding this from you guys!

Thanks a lot.

Was it helpful?

Solution

You need to include the package-

javac test/*.java

OTHER TIPS

try this in your command line

    cd intoParentDirWhereNodeIs
    javac Node.java
    javac -d . Node.java

This should create a folder package called test in your files

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top