|
1鱼币
本帖最后由 百日维新 于 2014-8-17 16:51 编辑
class Shape{
void draw() {}
void erase() {}
}
class Circle extends Shape{
void draw(){
System.out.println("Calling Circle.draw()");
}
void erase(){
System.out.println("Calling Circle.erase()");
}
}
class Square extends Shape{
void draw()
{
System.out.println("Calling Square.draw()");
}
void erase(){
System.out.println("Calling Square.erase()");
}
}
class Triangle extends Shape{
void draw(){
System.out.println("Calling Triangle.draw()");
}
void erase(){
System.out.println("Calling Triangle.erase()");
}
}
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();
}
}
public static void main(String[] args)
{
Random rand = new Random ();//?????
Shape[] s = new Shape[9] ;
for(int i ; i < s.length ; i ++)
{
switch(rand.nextInt[3]){
case 0 : s[i] = new Circle() ; break ;
case 1 : s[i] = new Circle() ; break ;
case 2 : s = new Circle() ; break ;
}
}
drawShapes(s);
}
}
想知道Random那儿是什么错误
[/i][/i][/i] |
|