哪位大侠来解释下这段程序的执行过程
代码如下:class shape{
void draw(){
System.out.println("shape draw()");
}
void erase()
{ System.out.println("shape erase()");}
}
class circle extends shape{
void draw(){
System.out.println("circle draw()");}
void erase()
{ System.out.println("cricle erase()");}
}
class triangle extends shape{
void draw(){
System.out.println("triangle draw()");}
void erase()
{ System.out.println("triangle erase()");}
}
class square extends shape{
void draw(){
System.out.println("square draw()");}
void erase()
{ System.out.println("square erase()");}
}
public class shapes{
public static shape randshape(){//返回值是对象
switch((int)(Math.random()*4)){//Java实现随即数的一种方法
default:
case 0:return new circle();//此中没有break是为什么
case 1:return new square();
case 2:return new triangle();
case 3:return new shape();
}
}
public static void main(String[]args){
shape[] s=new shape[9];
for(int i=0;i<s.length;i++)
s[i]=randshape();
for(int i=0;i<s.length;i++)
s[i].draw();
}
}