在Java中编译时出错:没有为Turtle找到合适的构造函数(没有参数)

时间:2016-04-12 02:07:01

标签: java

当我编译此错误出现时,我不确定可能出现的错误。

这是编译时出现的错误:

Error: no suitable constructor found for Turtle(no arguments)
     constructor Turtle.Turtle(int,int,Picture) is not applicable
      (actual and formal argument lists differ in length)
    constructor Turtle.Turtle(int,int,ModelDisplay) is not applicable
      (actual and formal argument lists differ in length)
    constructor Turtle.Turtle(ModelDisplay) is not applicable
      (actual and formal argument lists differ in length)
    constructor Turtle.Turtle(Picture) is not applicable
      (actual and formal argument lists differ in length)

这是我写的代码:

public class CreateShapes extends Turtle

{

    {
        //Put all your commands to call drawShape 4 times on 4 different turtle objects

      World world1 = new World();
      Turtle turtle1 = new Turtle(50,50,world1);
      turtle1.drawShape(100);
      Turtle turtle2 = new Turtle(100, 100,world1);
      turtle1.drawShape(200);
      Turtle turtle3 = new Turtle(200,200,world1);
      turtle1.drawShape(300);
      Turtle turtle4 = new Turtle(300,300, world1);
      turtle1.drawShape(400);

    }
}

1 个答案:

答案 0 :(得分:0)

似乎Turtle有四个不同的构造函数:一个有两个int s和一个Picture个实例,一个有两个int s和一个ModelDisplay实例,一个带有ModelDisplay实例的实例,另一个带有Picture实例的实例作为参数传递。

您正尝试使用两个Turtle和一个int实例启动World

除非WorldModelDisplayPicture的子类,否则无效。确保提供正确的第三个参数。