File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes packages!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "packages!!" Watch "packages!!" New topic
Author

packages!!

Ashok Paulraj
Ranch Hand

Joined: Jul 07, 2003
Posts: 78
Hello All,
I have a series of questions on packages....I am trying out certain things practically with my compiler and couldn't proceed much..help me out...Although, I have done some decent java projects, i haven't encountered much with PACKAGES or else IDE which I am will be using will take careof all abt. packages....okay, enuf of background stories;;;; lemme COME TO THE POINT...!!
i want to create 2 java files each under separate PACKAGES and test the access of protected/default & public members from one package to the other!! (both as subclass and as a non-subclass)..
I'm testing the progs. on a UNIX based system. I did create files with the following source code::
file 1::
package parent;
class protect1
{
void test1()
{
System.out.println("AM IN PARENT - protect1.java");
}
}
file2::
package child;
import parent.*;
public class protect2 extends protect1
{
public static void main(String[] args)
{
protect2 p2 = new protect2();
p2.test2();
}
void test2()
{
test1();
}
}
Should I necessarily need to create separate directories for each of the package or how should I go about executing this.....HELP OUT !!....
Any help is APPRECIATED !!
~ Shalini
dennis zined
Ranch Hand

Joined: Mar 07, 2003
Posts: 330
1. create "parent" directory
2. class protect1 filename should be "protect1.java" (you probably know this already) and then place this inside the "parent" directory you created in 1.
3. create "child" directory (outside parent directory)
4. class protect2 filename should be "protect2.java" and then place this inside the "child" directory you created in 3.
5. from outside the two directories, compile both classes:
a. javac parent/protect1.java
b. javac child/protect2.java
6. run protect2...: java child.protect2


SCJP 1.4<br />SCWCD 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: packages!!
 
Similar Threads
nested Packages
Regarding Package
javac and packages
What name to use to save files; what classes are allowed?
I am getting clone() has protected access in java.lang.Object