Object Classes

Can someone tell me why im getting an error for each of my other classes? The error is "The public type 'classname' must be defined in it's own file". How do I fix that? My friend said to put it in a package, but I don't know how.

publicclass Shapes{

publicstaticvoid main(String[] args){

Shape[] a =new Shape[5];

a[0] =new Rectangle(3, 4);

a[1] =new Square(5);

a[2] =new Circle(4);

a[3] =new Rectangle(5, 2);

a[4] =new Circle(5);

for (int i = 0; i != a.length; i++){

System.out.println(a[i]);

}

for (int i = 0; i != a.length; i++){

System.out.println(a[i].getArea());

}

for (int i = 0; i != a.length; i++){

a[i].move(2, 3);

}

for (int i = 0; i != a.length; i++){

System.out.println(a[i]);

}

((Rectangle)a[0]).exclusiveRectangleMethod();

((Rectangle)a[1]).exclusiveRectangleMethod();

}

}

publicclass Circleextends Shape{

publicint radius;

public Circle(int r){

radius = r;

}

publicint getArea(){

return (int)(Math.PI * radius * radius);

}

public String toString(){

return super.toString() +"; radius = " + radius;

}

}

abstractpublicclass Shape{

publicint x = 0;

publicint y = 0;

abstractpublicint getArea();

publicvoid move(int dx,int dy){

x += dx;

y += dy;

}

public String toString(){

return"x = " + x +"; y = " + y;

}

}

publicclass Rectangleextends Shape{

publicint height;

publicint width;

public Rectangle(int h,int w){

height = h;

width = w;

}

publicint getArea(){

return height * width;

}

public String toString(){

return"x = " + x +"; y = " + y

+"; height = " + height +"; width = " + width;

}

publicvoid exclusiveRectangleMethod(){

System.out.println("I'm a rectangle! I'm special!");

}

}

publicclass Squareextends Rectangle{

public Square(int x){

super(x, x);

}

}

[5798 byte] By [SoupSoapa] at [2007-11-27 1:56:01]
# 1
You must put the class Shapes in a file called "Shapes.java"You must put the class Circle in a file called "Circle.java", etc. etc.To compile them all, you can type "javac *.java"
KathyMcDonnella at 2007-7-12 1:29:48 > top of Java-index,Java Essentials,New To Java...
# 2
Where do I type javac.java?Is there any way to keep them all in the same file?
SoupSoapa at 2007-7-12 1:29:48 > top of Java-index,Java Essentials,New To Java...
# 3

Answer to your second question:

The Sun Java compiler will NOT allow you to have more than one toplevel public class in the same Java file.

So, no, you cannot.

Answer to your first question:

I just meant that, however you're compiling it now,

you should just adjust the compile command accordingly.

KathyMcDonnella at 2007-7-12 1:29:48 > top of Java-index,Java Essentials,New To Java...
# 4
Compiling it...I just click run
SoupSoapa at 2007-7-12 1:29:48 > top of Java-index,Java Essentials,New To Java...
# 5
Which IDE are you using? Eclipse?
KathyMcDonnella at 2007-7-12 1:29:48 > top of Java-index,Java Essentials,New To Java...
# 6
YesI fixed it though. I just took the public out of each subclass + abstract class. They weren't needed. Thanks for your help.
SoupSoapa at 2007-7-12 1:29:48 > top of Java-index,Java Essentials,New To Java...