Ball[] balls = new Ball[20]; void setup(){ size(500,500); smooth(); for(int i=0; i=width-radius && dx>0)) { dx=-dx; } if (yheight -radius) { y=height-radius; dy=-dy; speed *= dampen; } }//bounce void display() { noStroke(); fill(ballColor); ellipse(x, y, 2*radius, 2*radius); }//display } *************************** // This class is a subclass of the ball class // Notice use of super() to call the superclass constructor class ballInBox extends ball { // Inherits everything from ball class // additional attributes box myBox; ballInBox(float _x, float _y, float _r, color _c, box _b) { super(_x, _y, _r, _c); myBox = _b; } // ballInBox() // override the behavior of inherited bounce() void bounce() { if (x < radius) { x = radius; dx = -dx; } if (x > myBox.w-radius) { x = myBox.w-radius; dx = -dx; } if (y < radius) { y = radius; dy = -dy; } if (y > myBox.h - radius) { y = myBox.h-radius; dy = -dy; speed = speed*dampen; } } // bounce() } // class ballInBox