I created the first package inside the directory C:\test\eugene\scjp containing the following source code:

package com.test.eugene.scjp;

public class SuperClass
{
     private String name;

     public SuperClass(String name)
     {
            this.name = name;
     }

     protected String getName()
     {
            return name;
     }
}

Then I created the second package inside the directory C:\test\raj\scjp containing the following source code:

package com.test.raj.scjp;

import com.test.eugene.scjp.SuperClass;

public class SubClass extends SuperClass
{
     public SubClass(String name)
     {
          super(name);
     }

     public void printName()
     {
          System.out.println(getName());   
     }
}

The first package compiled with no error. To compile the second package I first set the classpath=".;C:\test\eugene" pointing to the first package. Then I compile the second package and I am getting the error:

C:\test\raj\scjp>javac SubClass.java
SubClass.java:3: package com.test.eugene.scjp does not exist
import com.test.eugene.scjp.SuperClass;
^
SubClass.java:5: cannot find symbol
symbol: class SuperClass
public class SubClass extends SuperClass
^
SubClass.java:14: cannot find symbol
symbol : method getName()
location: class com.test.raj.scjp.SubClass
System.out.println(getName());
^
3 errors

It appears that the first package I am trying to import into the second package is not possible. Did I miss something?. Your help is kindly appreciated.

Thank You.

Edited 6 Years Ago by solomon_13000: n/a

The folder hierarchy has to reflect the package statement I believe. So

C:\test\eugene\scjp

Needs to be :

C:\com\tets\eugene\scjp;

i.e. add a folder called com then follow the structure above.

or alternatively change the import statement in SubClass.java to:

import test.eugene.scjp.SuperClass;

I think that should fix it, although I am not sure - hopefully someone with more experience on package/dir structure will kindly help out if I am wrong.

Edited 6 Years Ago by majestic0110: tidy up

Now it works. I SET CLASSPATH=.;C:\
The I compiled the second package.

Edited 6 Years Ago by solomon_13000: n/a

This article has been dead for over six months. Start a new discussion instead.