Question by
Flappy37 · Mar 16, 2021 at 11:36 PM ·
parentchildconstructor
Setting Parent Value in Child Class Constructor
I am trying since hours to figure out why it won't work... but can't seem to get it running simply because I am not able to set a Parent value in a Childs constructor. I have a Class called Item which has a weight. and a Subclass called Armor:Item where I want to set the weight value while creating the armor. Somehow with the type it is giving me no error.
Parent class
public class Item {
public enum ItemType { armor, weapon };
protected ItemType type;
protected float weight;
public Item(float weight, ItemType type)
{
this.weight = weight;
this.type = type;
}
}
Child Class
public class Armor : Item
{ public Armor(float weight) { this.weight = weight; type = ItemType.armor; } }
Comment