inheritance - Must constructors of child classes mirror their parent's constructor exactly in java? -
this question has answer here:
java noobie here. i'm trying create constructor child class inherits complete class called parent. child class has few properties parent class not, when add these constructor, error:
error: constructor parent in class parent cannot applied given types;
i'm not sure whether syntax wrong, or whether i've got principle of matter confused. either appreciated.
my code:
public class parent { public string name; public int id; public string type; public parent(string name) { this.name = name; this.type = "not endangered"; } } and, separately,
public child(string name, string health, string age) { //perhaps need declare parent(name) here first? doesn't seem work, either; this.name = name; this.health = health; this.age = age; this.endangered = true; this.type = "endangered"; } }
Comments
Post a Comment