java shapes code

Solutions on MaxInterview for java shapes code by the best coders in the world

showing results for - "java shapes code"
Erik
08 Nov 2020
1class Polymorph {
2   public static void main(String argv[]) {
3
4      // create some shape instances
5      Shape scribble[] = new Shape[2];
6      scribble[0] = new Rectangle(10, 20, 5, 6);
7      scribble[1] = new Circle(15, 25, 8);
8
9      // iterate through the list and handle shapes polymorphically
10      for (int i = 0; i < scribble.length; i++) {
11         scribble[i].draw();
12         scribble[i].rMoveTo(100, 100);
13         scribble[i].draw();
14      }
15
16      // call a rectangle specific function
17      Rectangle arect = new Rectangle(0, 0, 15, 15);
18      arect.setWidth(30);
19      arect.draw();
20   }
21}
22