This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help on Packages!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help on Packages!!" Watch "Help on Packages!!" New topic
Author

Help on Packages!!

Swati Samudra
Greenhorn

Joined: Dec 27, 2000
Posts: 16
I have class A in Package P1 and its sub-class Class B in Package P2. I am able to compile class A from P1 directory on the prompt but I am Getting erro when I compile Class B from P2 directory at the prompt. I have import statement in class B importing class A and the error message says can't find class A and gives error at import statement.
How can I compile class B in package P2?
am confused....!
Swati
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
Hi Swati,
Just check whether your import statement is import p1.*; or not. If you want to import only the class A from the package P1 then your import statement should be import P1.A ;.
Also, please check , are you trying to access the members of
class A through a reference of A class or reference of class B. Finally, do make it point to check the access modifier of the
class A in package P1.
Please revert in case this is still a problem. You may post your code so that we can figure out the exact problem.
Ravindra Mohan.


[This message has been edited by Ravindra Mohan (edited May 24, 2001).]
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
It sometimes helps to think of packages as if they were subdirectories, that way you get an idea of the likely visibility.
Marcus


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Swati,
Assuming you have the following setup:

and A.java is defined with:

and B.java is defined with:

use the following commands to compile from the c:\someDir prompt:

Java assumes the package names follow the directory structure. If you try to compile 'B.java' from within the 'P2' directory it expects to find the 'P1' directory referred to in the 'import' statement within the current directory.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help on Packages!!
 
Similar Threads
Please explain this code
Package visibility
Q from Marcus Mock test 2
Reg. Packages
package directory