2012年7月20日金曜日

開発環境

『初めてのC# 第2版』(Jesse Liberty+Brian MacDonald著、日向俊二訳、オライリー・ジャパン、2006年、ISBN978-487311-294-7)の 第11章(継承とポリモーフィズム)11.9(練習問題)、練習11-1を解いてみる。

練習11-1.

コード

using System;

namespace Sample
{
    class Telephone
    {
        protected string phonetype;
        public void Ring()
        {
            Console.WriteLine("Ringing the {0}", phonetype);
        }
    }
    class ElectronicPhone : Telephone
    {
        public ElectronicPhone()
        {
            this.phonetype = "Digital";
        }
    }
    class Tester
    {
        public void Run()
        {
            ElectronicPhone ep = new ElectronicPhone();
            ep.Ring();
        }
        static void Main()
        {
            Tester t = new Tester();
            t.Run();
        }
    }
}

入出力結果(Console Window)

Ringing the Digital
続行するには何かキーを押してください . . .

0 コメント:

コメントを投稿