Topic: 请诸位帮一下忙,多谢了

  Print this page

1.请诸位帮一下忙,多谢了 Copy to clipboard
Posted by: binghuo007
Posted on: 2006-03-06 08:07

这段代码编译的时候能够成功,可运行的时候就会显示没有main()的错误,可我已经写main()方法了呀
请问这是怎么回事呀

//ShapeTest.java
interface Shape{

void draw();
void erase();

}

//Circle
class Circle implements Shape{

public void draw(){
System.out.println("Circle draw()...");
}
public void erase(){
System.out.println("Circle erase()...");
}
}

//Square
class Square implements Shape{
public void draw(){
System.out.println("Square draw()...");
}
public void erase(){
System.out.println("Square erase()...");
}
}

//Line
class Line implements Shape{
public void draw(){
System.out.println("Line draw()...");
}
public void erase(){
System.out.println("Line erase()...");
}
}

public class ShapeTest{

static void drawShape(Shape obj){
obj.draw();
obj.erase();
if(obj instanceof Circle){
System.out.println("Circle");
}
else if(obj instanceof Square){
System.out.println("Square");
}
else if(obj instanceof Line){
System.out.println("Line");
}
}

public static void main(String args[]){
Shape c=new Circle();
Shape s=new Square();
Shape l=new Line();
drawShapeCoffee;
drawShapeMoon;
drawShape(l);
}
}

//public Shape(){}
//public static void main(){

//}

2.Re:请诸位帮一下忙,多谢了 [Re: binghuo007] Copy to clipboard
Posted by: Skybus
Posted on: 2006-03-06 08:57

我复制下来运行了一下,结果是正确的啊,另外,你代码中的倒数第四,五行是不是下面的:
drawShape(c);
drawShape(s);

编辑帖子时禁用笑脸标志就不会显示出月亮和咖啡了

另外我用的Java IDE是Eclipse!

3.Re:请诸位帮一下忙,多谢了 [Re: binghuo007] Copy to clipboard
Posted by: luoq_dl
Posted on: 2006-03-06 08:58

除了main函数要改,其他的没有问题!

public static void main(String args[]){
Shape c=new Circle();
Shape s=new Square();
Shape l=new Line();
drawShape ( c);
drawShape ( s);
drawShape(l);
}

4.Re:请诸位帮一下忙,多谢了 [Re: binghuo007] Copy to clipboard
Posted by: surroad
Posted on: 2006-03-07 15:05

java ShapeTest


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923