inheritance - Must constructors of child classes mirror their parent's constructor exactly in java? -


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

Popular posts from this blog

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -