TWiki . Doc . ShapesBeginnerExample

/* 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

   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

----- Revision r1.4 - 10 Jan 2004 - 15:43 GMT - IsaacGouy
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.