inheritance - Your object's family tree - diagrams, base class, sub class
Head First C#: A Learner’s Guide to Real-World Programming with C# and .NET Core (Andrew Stellman(著)、Jennifer Greene(著)、O’Reilly Media)のChapter 6(inheritance - Your object’s family tree)、p.309(Sharpen your pencil)の解答を求めてみる。
コード
WeaponDamage.cs
using System;
namespace MyFirstConsoleApp
{
public class WeaponDamage
{
public int Roll { get; set; }
public bool Magic { get; set; }
public bool Flaming { get; set; }
public int Damage { get; set; }
public WeaponDamage()
{
}
protected virtual void CalculateDamage() { }
}
}
コード
SwordDamage.cs
using System;
namespace MyFirstConsoleApp
{
public class SwordDamage:WeaponDamage
{
public SwordDamage()
{
}
protected override void CalculateDamage()
{
base.CalculateDamage();
}
}
}
コード
ArrowDamage.cs
using System;
namespace MyFirstConsoleApp
{
public class ArrowDamage:WeaponDamage
{
public ArrowDamage()
{
}
protected override void CalculateDamage()
{
base.CalculateDamage();
}
}
}