• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Another Package Question

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


/pomiet>javac mammals/animals.java


You've got to do this from the parent directory of pomiet.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And of course, Speak.class must be inside the directory talk which must be a subdirectory of pomiet.
Good Luck.
 
Rob Keefer
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It works, thanks...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic