Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从派生类调用构造函数_Java_Oop_Inheritance_Constructor_Compiler Errors - Fatal编程技术网

Java 从派生类调用构造函数

Java 从派生类调用构造函数,java,oop,inheritance,constructor,compiler-errors,Java,Oop,Inheritance,Constructor,Compiler Errors,嗨,我一直在尝试使用我的零参数构造函数来调用我的 具有初始权重值的SunkenObject构造函数,但由于某些原因,我不断遇到此错误 类SunkenObject中的构造函数SunkenObject不能应用于给定类型` 这是我的SunkenObject构造函数: public abstract class SunkenObject extends CatchableThing { protected float weight; public SunkenObject(float w)

嗨,我一直在尝试使用我的零参数构造函数来调用我的 具有初始权重值的SunkenObject构造函数,但由于某些原因,我不断遇到此错误

类SunkenObject中的构造函数SunkenObject不能应用于给定类型`

这是我的SunkenObject构造函数:

public abstract class SunkenObject extends CatchableThing
{
   protected float weight;

   public SunkenObject(float w)
   {
     weight = w;
   }

  public float getWeight() { return weight; }

    public String toString () 
    {
        return (getClass().getSimpleName());
    }
}
这是一条锈迹斑斑的链条,由SunkenObject延伸而成

public class RustyChain extends SunkenObject 
{

    public RustyChain (float w)
  {
    super(w);  
  }
   public RustyChain()
   {
     weight = 8.0f;
   }


}
谁能告诉我我做错了什么,因为从我的角度来看,代码没有任何问题。谢谢大家!

你的意思是这样的:

public RustyChain() {
    super(8.0f);
}

weight=8.0f不调用超级类构造函数。

具体类构造函数的第一个默认语句是super;呼叫声明

所以,要让它工作,你要么移除

public RustyChain()
{
 weight = 8.0f;
}
或者像这样在超类中添加一个无参数构造函数

public SunkenObject()
{}

@user3330114有一段时间我们把它弄丢了P:D即使相隔几步。。
public SunkenObject()
{}