Java 继承类未编译

Java 继承类未编译,java,inheritance,Java,Inheritance,我只是在玩代码,今天在课堂上学习了继承,无法编译,也不知道怎么回事,只是说在colorfeathers=C行中找不到C public class Bird extends inheritance{ private String colorFeathers; public Bird(String c, String n){ super("Bird:" , n, 2, 0); colorFeathers = c; } public

我只是在玩代码,今天在课堂上学习了继承,无法编译,也不知道怎么回事,只是说在colorfeathers=C行中找不到C

public class Bird extends inheritance{

    private String colorFeathers;

    public Bird(String c, String n){
        super("Bird:" , n, 2, 0);
        colorFeathers = c;
    }

    public String GetColor(){return colorFeathers;}

    public void setColors(){colorFeathers = c;}

    public String toString(){             
        String hold = super.toString(); 
        hold += "color:" + colorFeathers;
        return hold;   
    }
}

这里缺少参数

 public void setColors(String c){colorFeathers = c;}

假设超类中的所有其他内容都正常

问题出在
公共void setColors(){colorFeathers=c;}

您没有将
c
作为字符串传递,因此在该函数中的
c
setColors方法的上下文中,变量是未知的

public Bird(String c, String n){
   super("Bird:" , n, 2, 0);
   colorFeathers = c;
}
只存在于该函数中。功能完成后,
c
将不再存在。因此,调用
c
变量

public void setColors(){colorFeathers = c;}
不能工作

也许您还想让
setColors
有一个
c
参数?像这样

public void setColors(String c){colorFeathers = c;}

什么是继承?那是你要扩展的课程吗?