Home > Archive > Java Help > February 2007 > Help with extend
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hello everyone,
I have a superclass GeometricObject which compiles.
Then I have a subclass Circle which extends the superclass, but the compiler
doesn't like it and i get the following error ( cannot find symbol
symbol: class GeometricObject).
Can anyone please help?
Here are my both classaes:
package Geo;
public class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;
public GeometricObject() {
dateCreated = new java.util.Date();
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public boolean isFilled() {
return filled;
}
public void setFilled(boolean filled) {
this.filled = filled;
}
public java.util.Date getDateCreated() {
return dateCreated;
}
public String toString() {
return "created on " + dateCreated + "\ncolor: " + color +
" and filled: " + filled;
}
}
package Geo;
public class Circle extends GeometricObject {
private double radius;
public Circle() {
}
public Circle(double radius) {
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
public double getArea() {
return radius * radius * Math.PI;
}
public double getDiameter() {
return 2 * radius;
}
public double getPerimeter() {
return 2 * radius * Math.PI;
}
public void printCircle() {
System.out.println("The circle is created " + getDateCreated() +
" and the radius is " + radius);
}
}
Thanks in advance,
Kiani
| |
| Andrew Thompson 2007-02-17, 8:09 am |
| On Feb 17, 8:53 pm, "Kiani" <adsl588...@tiscali.nl> wrote:
...
> I have a superclass GeometricObject which compiles.
> Then I have a subclass Circle which extends the superclass, but the compiler
> doesn't like it and i get the following error ( cannot find symbol
> symbol: class GeometricObject).
> Can anyone please help?
Here is a document that deals with compiling
and running packaged classes
<http://rabbitbrush.frazmtn.com/classpath.html>
> Here are my both classaes:
>
> package Geo;
Note that using common Java nomenclature,
package 'Geo' should be all lower case,
hence 'geo', but also not an abbreviation,
hence 'geometry' or 'geology' or..
Andrew T.
| |
| murari garg 2007-02-17, 7:07 pm |
| On Feb 17, 2:53 pm, "Kiani" <adsl588...@tiscali.nl> wrote:
> Hello everyone,
>
> I have a superclass GeometricObject which compiles.
> Then I have a subclass Circle which extends the superclass, but the compiler
> doesn't like it and i get the following error ( cannot find symbol
> symbol: class GeometricObject).
> Can anyone please help?
> Here are my both classaes:
>
> package Geo;
> public class GeometricObject {
> private String color = "white";
> private boolean filled;
> private java.util.Date dateCreated;
>
> public GeometricObject() {
> dateCreated = new java.util.Date();
> }
> public String getColor() {
> return color;
> }
> public void setColor(String color) {
> this.color = color;
> }
> public boolean isFilled() {
> return filled;
> }
> public void setFilled(boolean filled) {
> this.filled = filled;
> }
> public java.util.Date getDateCreated() {
> return dateCreated;
> }
> public String toString() {
> return "created on " + dateCreated + "\ncolor: " + color +
> " and filled: " + filled;
> }
>
> }
>
> package Geo;
> public class Circle extends GeometricObject {
> private double radius;
> public Circle() {
> }
> public Circle(double radius) {
> this.radius = radius;
> }
> public double getRadius() {
> return radius;
> }
> public void setRadius(double radius) {
> this.radius = radius;
> }
> public double getArea() {
> return radius * radius * Math.PI;
> }
> public double getDiameter() {
> return 2 * radius;
> }
> public double getPerimeter() {
> return 2 * radius * Math.PI;
> }
> public void printCircle() {
> System.out.println("The circle is created " + getDateCreated() +
> " and the radius is " + radius);
> }}
>
> Thanks in advance,
> Kiani
try to break your programme in different classes. and keeping all
these class in one folder run your superclass file.
or you can add the class files directly like:
javav yourfilename.java -classpath c:\yourclassfiles
| |
| murari garg 2007-02-17, 7:07 pm |
| On Feb 17, 2:53 pm, "Kiani" <adsl588...@tiscali.nl> wrote:
> Hello everyone,
>
> I have a superclass GeometricObject which compiles.
> Then I have a subclass Circle which extends the superclass, but the compiler
> doesn't like it and i get the following error ( cannot find symbol
> symbol: class GeometricObject).
> Can anyone please help?
> Here are my both classaes:
>
> package Geo;
> public class GeometricObject {
> private String color = "white";
> private boolean filled;
> private java.util.Date dateCreated;
>
> public GeometricObject() {
> dateCreated = new java.util.Date();
> }
> public String getColor() {
> return color;
> }
> public void setColor(String color) {
> this.color = color;
> }
> public boolean isFilled() {
> return filled;
> }
> public void setFilled(boolean filled) {
> this.filled = filled;
> }
> public java.util.Date getDateCreated() {
> return dateCreated;
> }
> public String toString() {
> return "created on " + dateCreated + "\ncolor: " + color +
> " and filled: " + filled;
> }
>
> }
>
> package Geo;
> public class Circle extends GeometricObject {
> private double radius;
> public Circle() {
> }
> public Circle(double radius) {
> this.radius = radius;
> }
> public double getRadius() {
> return radius;
> }
> public void setRadius(double radius) {
> this.radius = radius;
> }
> public double getArea() {
> return radius * radius * Math.PI;
> }
> public double getDiameter() {
> return 2 * radius;
> }
> public double getPerimeter() {
> return 2 * radius * Math.PI;
> }
> public void printCircle() {
> System.out.println("The circle is created " + getDateCreated() +
> " and the radius is " + radius);
> }}
>
> Thanks in advance,
> Kiani
try to break your programme in different classes. and keeping all
these class in one folder run your superclass file.
or you can add the class files directly like:
javav yourfilename.java -classpath c:\yourclassfiles
| |
| Eric Sosman 2007-02-17, 7:07 pm |
| Andrew Thompson wrote:
> [...]
> Note that using common Java nomenclature,
> package 'Geo' should be all lower case,
> hence 'geo', but also not an abbreviation,
> hence 'geometry' or 'geology' or..
Aside: No doubt that's why we have java.language and
java.mathematics and java.utility and java.input_output
and java.abstract_windowing_toolkit ...
In other words: Where does the "not an abbreviation"
guideline come from, and if from an authoritative source
why is it so widely ignored?
--
Eric Sosman
esosman@acm-dot-org.invalid
| |
|
| murari garg wrote:
>
> try to break your programme in different classes.
> and keeping all these class in one folder
The OP seems already to have done this.
> run your superclass file.
Huh? They are trying to run the *sub*class file.
> or you can add the class files directly like:
> javav yourfilename.java -classpath c:\yourclassfiles
Actually, the classpath parameter comes before the file parameter, there is no
"javav" command, and "yourclassfiles" directory should be
"rootOfYourClassFileDirectoryTree".
So don't try that command at home.
Are the class files (the .class files, not the .java files) in the "Geo"
directory relative to the classpath root for the "java" command?
- Lew
| |
|
| murari garg wrote:
>
> try to break your programme in different classes. and keeping all
> these class in one folder run your superclass file.
> or you can add the class files directly like:
>
> javav yourfilename.java -classpath c:\yourclassfiles
Duplicate message.
- Lew
| |
|
| On Feb 17, 9:32 am, Lew <l...@nospam.lewscanon.com> wrote:
> murari garg wrote:
>
>
>
> Duplicate message.
>
> - Lew
I wonder if the problem is that the package statement is entered
before the circle class. If the classes are in the same file, then
that might be interpreted as package Geo inside package Geo, and hence
the scope problems described.
So, OP, if your code is in one file, drop the second declaration of
package Geo, or split the classes into separate files (latter
preferred).
| |
| Andrew Thompson 2007-02-17, 7:07 pm |
| On Feb 18, 1:22 am, Eric Sosman <esos...@acm-dot-org.invalid> wrote:
> Andrew Thompson wrote:
...[color=darkred]
> ..Where does the "not an abbreviation"
> guideline come from, ...
Well, OK. Maybe I got into describing
my ideal naming system, rather than any
accepted convention.
Andrew T.
| |
| Andrew Thompson 2007-02-17, 7:07 pm |
| On Feb 18, 1:37 am, "Jeff" <jeffrey.summ...@gmail.com> wrote:
...
> ...If the classes are in the same file, ..
No. The OP would be getting other,
different errors than the ones
described, triggered by the second
package statement, and any 'public'
class that was not in a file according
to its name.
Andrew T.
| |
| a249@mailinator.com 2007-02-17, 7:07 pm |
| On 17 Feb., 15:32, Lew <l...@nospam.lewscanon.com> wrote:
> Duplicate message.
You are talking to our serial spammer, thief and warez dealer
ramgarg69@gmail.com Don't expect that he suddenly saw the light.
http://groups.google.com/groups/sea...75xS36mXc24h6ww
| |
|
| a249@mailinator.com wrote:
> You are talking to our serial spammer, thief and warez dealer
> ramgarg69@gmail.com Don't expect that he suddenly saw the light.
>
<http://groups.google.com/groups/sea...75xS36mXc24h6ww>
Oh, he's javaBSartist!
If his answer to the OP on this thread is any indication, well, ...
- Lew
| |
|
| Kiani wrote:
> Hello everyone,
>
> I have a superclass GeometricObject which compiles.
> Then I have a subclass Circle which extends the superclass, but the compiler
> doesn't like it and i get the following error ( cannot find symbol
> symbol: class GeometricObject).
> Can anyone please help?
> Here are my both classaes:
>
> package Geo;
> public class GeometricObject {
> private String color = "white";
> private boolean filled;
> private java.util.Date dateCreated;
>
> public GeometricObject() {
> dateCreated = new java.util.Date();
> }
> public String getColor() {
> return color;
> }
> public void setColor(String color) {
> this.color = color;
> }
> public boolean isFilled() {
> return filled;
> }
> public void setFilled(boolean filled) {
> this.filled = filled;
> }
> public java.util.Date getDateCreated() {
> return dateCreated;
> }
> public String toString() {
> return "created on " + dateCreated + "\ncolor: " + color +
> " and filled: " + filled;
> }
> }
>
> package Geo;
> public class Circle extends GeometricObject {
> private double radius;
> public Circle() {
> }
> public Circle(double radius) {
> this.radius = radius;
> }
> public double getRadius() {
> return radius;
> }
> public void setRadius(double radius) {
> this.radius = radius;
> }
> public double getArea() {
> return radius * radius * Math.PI;
> }
> public double getDiameter() {
> return 2 * radius;
> }
> public double getPerimeter() {
> return 2 * radius * Math.PI;
> }
> public void printCircle() {
> System.out.println("The circle is created " + getDateCreated() +
> " and the radius is " + radius);
> }
> }
> Thanks in advance,
> Kiani
>
>
I set up a package in Eclipse called Geo and created both classes
sucessfully. I even wrote a tester
package Geo;
public class testCircle {
public static void main (String [] args)
{
Circle c1 = new Circle(12.32);
c1.printCircle();
}
}
The circle is created Sat Feb 17 21:04:14 AST 2007 and the radius is 12.32
One question...why would there be a constructor with no parameters? How
does one create a circle which has no dimensions?
|
|
|
|
|