• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

packages!!

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic