当前位置: 技术问答>java相关
一个未知的错误
来源: 互联网 发布时间:2015-06-03
本文导语: 这段代码编译老是出错: //:Shapes.java //Polymorphism in java package c07; class Shape{ void draw(){} void erase(){} } class Circle extends Shape{ void draw(){ System.out.println("Circle.draw()"); } void erase(){ System.out.println("Circle.erase()"); ...
这段代码编译老是出错:
//:Shapes.java
//Polymorphism in java
package c07;
class Shape{
void draw(){}
void erase(){}
}
class Circle extends Shape{
void draw(){
System.out.println("Circle.draw()");
}
void erase(){
System.out.println("Circle.erase()");
}
}
class Square extends Shape{
void draw(){
System.out.println("Square.draw()");
}
void erase(){
System.out.println("Square.erase()");
}
}
class Triangle extends Shape{
void draw(){
System.out.println("Triangle.draw()");
}
void erase(){
System.out.println("Triangle.erase()");
}
}
public class Shapes{
public static Shape randShape(){
switch((int)(Math.random()*3)){
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
//:Shapes.java
//Polymorphism in java
package c07;
class Shape{
void draw(){}
void erase(){}
}
class Circle extends Shape{
void draw(){
System.out.println("Circle.draw()");
}
void erase(){
System.out.println("Circle.erase()");
}
}
class Square extends Shape{
void draw(){
System.out.println("Square.draw()");
}
void erase(){
System.out.println("Square.erase()");
}
}
class Triangle extends Shape{
void draw(){
System.out.println("Triangle.draw()");
}
void erase(){
System.out.println("Triangle.erase()");
}
}
public class Shapes{
public static Shape randShape(){
switch((int)(Math.random()*3)){
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