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 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 "packages!!" Watch "packages!!" New topic


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 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 -");
package child;
import parent.*;
public class protect2 extends protect1
public static void main(String[] args)
protect2 p2 = new protect2();
void test2()
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 "" (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 "" and then place this inside the "child" directory you created in 3.
5. from outside the two directories, compile both classes:
a. javac parent/
b. javac child/
6. run protect2...: java child.protect2

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