跪求static void drawOneShape(Shape s){ s.draw();这个方法在这段程序有什么作用import java.util. *;//定义Shape类class Shape{void draw(){}void erase(){}}//定义Cricle类class Cricle extends Shape{void draw(){System.out.println("Calling Cricle.draw()");}void erase(){System.out.println("Calling Cricle.erase()");}}//定义Square类class Square extends Shape{void draw(){System.out.println("Calling Square.draw()");}void erase(){System.out.println("Calling Square.erase()");}}//定义Triangle类class Triangle extends Shape{void draw(){System.out.println("Calling Triangle.draw()");}void erase(){System.out.println("Calling Triangle.erase()");}}//包含main()的测试方法类public class Shapes{static void drawOneShape(Shape s){s.draw();}static void drawShapes(Shape[] ss){for(int i=0;i<=ss.length;i++){ss[i].draw();System.out.println(ss.length);}}public static void main(String[] args){Random rand = new Random();Shape[] s = new Shape[9];for(int i=0;i<s.length;i++){switch(rand.nextInt(3)){case 0:s[i] = new Cricle();break;case 1:s[i] = new Square();break;case 2:s[i] = new Triangle();break;}}drawShapes(s);}}
添加回答
举报
0/150
提交
取消