accessing packages cont'd

L

Luke

Hi,

My second problem is this:

I have the following hierarachy:
t1/test/test2

then I have source files as follows:
t1/test/test2/Pref.java

t1/test/PrefBean.java

t1/UsePref.java

===========================
the files are like this:
Pref.java:
===========================
package test2;

public class Pref
{
// attributes
private String reason;

// constructor method
public Pref()
{
}

// methods
public String getReason()
{
return reason;
}

public void setReason(String reason)
{
this.reason = reason;
}
}
=============================
PrefBean.java
=============================
package test;

import test2.*;

public class PrefBean
{
// constructor method
public PrefBean()
{
Pref p = new Pref();
}
}
=============================
UsePref.java
=============================
package t1;

import test.*;
import test.test2.*;

public class UsePref
{
// constructor method
public UsePref()
{
PrefBean pb = new PrefBean();
Pref p2 = new Pref();
}
}
=============================
As you can see I want to access 'PrefBean' and 'Pref' from 'UsePref'.
However I try, I can't get it working.
I'm using java 1.4.2

Can someone help please!
Can you get this working on your machine

kind regards,
Luke
 
L

Luke

Hi,

I solved that prob, I believe

I changed each class's package directive to be:
for t1/test/test2/Pref.java: package t1.test.test2;
for t1/test/PrefBean.java: package t1.test;
for t1/UsePref.java: package t1;

and the import directives to
for t1/test/PrefBean.java:
import t1.test.test2.*;
for t1/UsePref.java:
import t1.test.test2.*;
import t1.test.*;

then I went to the parent directory of t1 and did:

javac -d . t1/*.java

this caused all the classes to compile.
and my computer to smile :-]

the article that helped was:
http://www.cs.wisc.edu/~hasti/cs368/JavaTutorial/NOTES/Packages.html

I'll be posting my 3rd problem shortly.
Thanks for being a listening post,

kind regards,
Luke
 
R

Roedy Green

I changed each class's package directive to be:
for t1/test/test2/Pref.java: package t1.test.test2;
for t1/test/PrefBean.java: package t1.test;
for t1/UsePref.java: package t1;

Normally you put more than one class in package, but you seem to have
grasped the naming conventions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top