oop - Java Inheritance constructor issue -


i try send parent's parameters through child constructor.

parent:

    public class animal {     protected string name;     protected int age;     protected int weight;     protected int height;      public animal(string name,int age,int weight,int height)     {         name = name;         age = age;         weight = weight;         height = height;     } } 

child:

    public class mammals extends animal {      protected string haircolor;      public mammals(string haircolor,int age,int weight,int height)     {         super(age,weight,height);         haircolor = haircolor;     }      public string walk()     {         return "walking...";     } } 

from reason keep getting error.

the error comes from

super(age,weight,height); 

because super-constructor has 4 parameters , you're passing three.

since don't have name child, can pass null.

super(null, age, weight, height); 

also, consider following code-conventions.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -