// NonOO.java -- illustrate type analysis versus OO

class Point {
   protected float x,y;
   Point (float x, float y) { this.x=x; this.y=y; }
   void move (float dx, float dy) { x += dx; y += dy; }
}

class Rectangle extends Point {
   protected float height, width;
   Rectangle (float x, float y, float h, float w) {
      super (x,y); height=h; width=w;
   }
}

class Circle extends Point {
   protected float radius;
   Circle (float x, float y, float r) {
      super (x,y); radius=r;
   }
}

class NonOO {

   static void print (Point p) {
      if (p instanceof Rectangle) {
         final Rectangle r = (Rectangle) p;
         System.out.println ("("+r.x+","+r.y+";h="+
                             r.height+",w="+r.width+")");
      } else if (p instanceof Circle) {
         final Circle c = (Circle) p;
         System.out.println ("("+c.x+","+c.y+";r="+c.radius+")");
      } else {
         System.out.println ("("+p.x+","+p.y+")");
      }
   }

   public static void main (String [] args) {
      final Point p = new Point (2.3f, 4.5f);
      final Rectangle r = new Rectangle (2.3f, 4.5f, 45.1f, 89.1f);
      final Circle c = new Circle (2.3f, 4.5f, 0.3f);
      final Point [] list = new Point [] {p, r, c};
      for (Point q: list) q.move (0.1f, 0.1f);  // inheritance
      for (Point q: list) print (q);            // subclass polymorphism
   }
}