Since we want all Paladin objects to have a name, and Character already has a constructor that handles this, we can call the base constructor directly from the Paladin class and save ourselves the trouble of rewriting a constructor:
- Add a constructor to the Paladin class that takes in a string parameter, called name:
- Use a colon and the base keyword to call the parent constructor, passing in name:
public class Paladin: Character
{
public Paladin(string name): base(name)
{
}
}
- Create a new Paladin instance, called knight, in LearningCurve:
- Use the base constructor to assign a value.
- Call PrintStatsInfo from knight and take a look at the console:
Paladin knight = new Paladin("Sir Arthur");
knight.PrintStatsInfo();
The debug log will be the same as our other Character instances, but with the name that we assigned to the Paladin constructor...