Reputation: 1
i am just playing around with code and learned about inheritance in class today, cant get this to compile and dont know what is wrong, just says that it can not find C in the line colorfeathers = 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;
}
}
Upvotes: 0
Views: 35
Reputation: 20163
The c
in this function
public Bird(String c, String n){
super("Bird:" , n, 2, 0);
colorFeathers = c;
}
Only exists in that function. Once the function is complete, c
no longer exists. Therefore, this call to the c
variable
public void setColors(){colorFeathers = c;}
Cannot work.
Perhaps you also mean for setColors
to have a c
parameter? Like this
public void setColors(String c){colorFeathers = c;}
Upvotes: 0
Reputation: 1900
the problem is in the public void setColors(){colorFeathers = c;}
You are not passing in c
as a string so the variable is unknown in the context of the setColors method
Upvotes: 1
Reputation: 54742
you are missing the parameter here
public void setColors(String c){colorFeathers = c;}
assuming all other things in superclass are okay
Upvotes: 0