大家帮我解释个程序,谢谢了
abstract class Shape{abstract void draw();
abstract void erase();
}
class Circle extends Shape{
void draw(){
System.out.println("I'm a circle");
}
void erase(){
System.out.println("I'm circle s");
}
}
class Square extends Shape{
void draw(){
System.out.println("I'm a square");
}
void erase(){
System.out.println("I'm square s");
}
}
class Triangle extends Shape{
void draw(){
System.out.println("I'm a Triangle");
}
void erase(){
System.out.println("I'm Triangle s");
}
}
class huxiang{
public static Shape randShape(){ //能帮我解释下这个方法吗?
switch((int)(Math.random()*3)){
default:System.out.println("hello");
case 0:return new Circle();
case 1:return new Square();
case 2:return new Triangle();
}
}
public static void main(String args[]){
Shape[] s=new Shape[9];
for(int i=0;i<s.length;i++){
s[i]=randShape();
s[i].draw();
s[i].erase();
}
}
}