/* Please try the NoviceExamples before the BeginnerExamples
To compile:
nicec --sourcepath=.. -a shapes.jar shapes
*/
abstract class Shape {
int x;
int y;
void moveTo(int newx, int newy);
moveTo(newx, newy) {
x = newx;
y = newy;
}
void moveBy(int dx, int dy);
}
moveBy(Shape this, dx, dy){
x += dx;
y += dy;
}
class Rectangle extends Shape {
private int width;
private int height;
void setHeight(int height);
void setWidth(int width);
setWidth(int width){
this.width = width;
}
}
setHeight(Rectangle this, height){
this.height = height;
}
class Circle extends Shape {
private int radius;
void setRadius(int radius);
}
setRadius(Circle this, radius){
this.radius = radius;
}
/* Notes - language
Compare with other OO languages
http://onestepback.org/articles/poly/
http://www.angelfire.com/tx4/cus/shapes/
void moveTo(int newx, int newy);
Within a class definition, declare a method
with a method implementation for the class.
void moveBy(int dx, int dy);
Within a class definition, declare a method.
moveBy(Shape this, dx, dy){
Outside of the class definition, provide a
method definition and implementation - for parameters
matching Shape (and subclasses), int and int.
*/
-- IsaacGouy - 24 Dec 2003
| Topic ShapesBeginnerExample . { Edit | Attach | Ref-By | Printable | Diffs | r1.4 | > | r1.3 | > | r1.2 | More } |
|
Revision r1.4 - 10 Jan 2004 - 15:43 GMT - IsaacGouy Parents: WebHome > CodeExamples |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding TWiki? Send feedback. |