aspose file tools*
The moose likes Beginning Java and the fly likes Another Package Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Another Package Question" Watch "Another Package Question" New topic
Author

Another Package Question

Rob Keefer
Greenhorn

Joined: Feb 18, 2002
Posts: 26
Hi,
I have an interface defined in one package that I am trying to use in another package. I get a compile error. Here is everything I know ...
In Directory /pomiet/talk
Speak.java Speak.class
Speak.java:
package pomiet.talk;
public interface Speak
{
void speak();
}
In Directory /pomiet/mammals:
Animals.java
Animals.java:
package pomiet.mammals;
import pomiet.talk.*;
abstract class Animal implements Speak
{
}
class dog extends Animal
{
public void speak()
{
System.out.println("WOOF!");
}
}
class cat extends Animal
{
public void speak()
{
System.out.println("meow");
}
}
class cow extends Animal
{
public void speak()
{
System.out.println("MOOOOO!");
}
}
public class Animals
{
public static void main(String[] args)
{
Animal b = new cow();
Animal c = new cat();
Animal d = new dog();
b.speak();
c.speak();
d.speak();
}
}

When I compile I get this:
/pomiet>javac talk/Speak.java
/pomiet>javac mammals/animals.java
mammals/animals.java:3: package pomiet.talk does not exist
import pomiet.talk.*;
^
Any suggestions?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023

/pomiet>javac mammals/animals.java

You've got to do this from the parent directory of pomiet.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
And of course, Speak.class must be inside the directory talk which must be a subdirectory of pomiet.
Good Luck.
Rob Keefer
Greenhorn

Joined: Feb 18, 2002
Posts: 26
It works, thanks...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Another Package Question