Java-继承和多态性

Java-继承和多态性,java,inheritance,polymorphism,parent-child,Java,Inheritance,Polymorphism,Parent Child,说明如下: 创建一个包含Main方法的主类。使生效 主要方法中包含以下内容: –使用重载构造函数从常规类创建对象 –测试所有实例方法,即setter、getter、重载、重写 –指定给子对象的父参照 –传递多态对象的方法调用 我被困在了我的父母班,那是雨林。接下来我该怎么办 雨林类 //INHERITANCE package com.ancient;

说明如下: 创建一个包含Main方法的主类。使生效 主要方法中包含以下内容:

–使用重载构造函数从常规类创建对象

–测试所有实例方法,即setter、getter、重载、重写

–指定给子对象的父参照

–传递多态对象的方法调用

我被困在了我的父母班,那是雨林。接下来我该怎么办

雨林类

//INHERITANCE                                                      
  package com.ancient;                                              
  public class Rainforest                                                
  {                                         
  public static void main(String[] args)                                 
  }
哺乳动物类父类

//PARENT CLASS                                                     
  package com.ancient;                                              
  public class Mammal                                                    
  {
//INSTANCE VARIABLES
private String type;
private double speed;

//CONSTRUCTOR
public Mammal(String type, double speed)
{
    this.type = type;
    this.speed = speed;
}

//SETTERS
public void setType(String type) 
{
    this.type = type;
}

public void setSpeed(double speed) 
{
    this.speed = speed;
}

//GETTERS
public String getType() 
{
    return type;
}

public double getSpeed() 
{
    return speed;
}

//OVERRIDDEN
public void hunt(int Food)//int Food is the quantity - how many does the eagle he hunts?
{
    System.out.println("The Bald eagle preys " + Food + "animals within a day to survive.");
}
}

鸟童班

package com.ancient;                                                
 public class Bird extends Mammal                                        
 {                                                                  
 public Bird(String type, double speed) 
{
    super(type, speed);
}

//OVERRIDDING
public void hunt(int Food)//int Food is the quantity - how many does the eagle he hunts?
{
    System.out.println("The Bald eagle will prey " + Food + "animals within a day to survive.");                                                  
}                                                                        
}
我的项目内容


现在,这里的问题是:我的构造函数是未定义的。我应该制作一个新的包并在其中插入Rainforest类吗?或者我在哺乳动物和鸟类课上的物体有问题

您的哺乳动物类中有一个接受参数的构造函数,但您试图在不传递参数的情况下实例化对象。

像这种公共哺乳动物字符串类型,双速?这就是您在哺乳动物类中定义构造函数的方式。要实例化一个新的哺乳动物对象,您需要将参数传递给构造函数,例如新的哺乳动物类型,1.0;不要发布代码的图片。直接输入代码。