aspose file tools*
The moose likes Beginning Java and the fly likes JAVA Package Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JAVA Package Query" Watch "JAVA Package Query" New topic
Author

JAVA Package Query

Tulika Rai
Greenhorn

Joined: Dec 24, 2009
Posts: 1
I have created 2 packages pkg1 and pkg2, my directory structure is :

c:\ABC\pkg1
c:\ABC\pkg2

I have created a file TestProtectedSuper.java in pkg1 and TestProtectedSub.java in pkg2

when I am individually compiling and running pkg1.TestProtectedSuper it is running fine, but when I am trying to use this file in pkg2.TestProtectedSub.java,
getting compilation error :

package pkg1 does not exist

cannot fine symbol for class TestProtectedSuper

code for TestProtectedSuper.java :

package pkg1;

public class TestProtectedSuper
{
protected int age;
public TestProtectedSuper(int ag)
{
age=ag;
}

/*public static void main(String args[])
{
System.out.println("TestProtectedSuper");
}*/

}

Code for TestProtectedSub.java is :

package pkg2;
import pkg1.TestProtectedSuper;
public class TestProtectedSub
{
public static void main(String[] args)
{
System.out.println("Testing Protected Variable in different package");

TestProtectedSuper obj1=new TestProtectedSuper(10);
System.out.println("age is : " + obj1.age);
}
}

Can anyone help me in solving my problem.....
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
because age variable has protected access modifier and hence can not be accessed by any class but subclass outside the package.



Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1478
    
    6


because age variable has protected access modifier and hence can not be accessed by any class but subclass outside the package.


The above should have raised an error in this line, and which is obviously going to occur



But the error which occurred first is


package pkg1 does not exist


So it looks like a classpath issue.


Swastik
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39817
    
  28
It might simply be an error about which directory the command line uses as current. Try running it from the directory one level above pkg1, ie ABC.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JAVA Package Query