wood burning stoves 2.0*
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JAVA Package Query" Watch "JAVA Package Query" New topic

JAVA Package Query

Tulika Rai

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


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)

/*public static void main(String args[])


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

Joined: Jan 08, 2009
Posts: 1449

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.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 37936
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.
jQuery in Action, 2nd edition
subject: JAVA Package Query
Similar Threads
How to call a protected method in other packages non-subclass
Abstract class and Access Modifiers
inhertitance through multiple packages - not able to analyze the output-
Help with Packages
inheritance and polymorphism across packages