計算機科学のブログ

inheritance - Your object's family tree - class model, access modifier, public, private, protected

Head First C Sharp: A Learner’s Guide to Real-World Programming with C Sharp and .NET (Andrew Stellman(著)、Jennifer Greene(著)、O’Reilly Media)の Chapter 6(inheritance - Your object’s family tree)、p.309(Sharpen your pencil)の解答を求めてみる。

コード

Program.cs

class WeaponDamage
{
    public int Roll;
    public int Magic;
    public int Flaming;
    public int Damage;
    protected virtual void CalculateDamage() { }
}
class SwordDamage : WeaponDamage
{
    protected override void CalculateDamage()
    {
        base.CalculateDamage();
    }
}
class ArrowDamage : WeaponDamage
{
    protected override void CalculateDamage()
    {
        base.CalculateDamage();
    }
}