開発環境
- OS: macOS High Sierra - Apple
- IDE(統合開発環境): Visual Studio for Mac
- プログラミング言語: C#
初めてのC# 第2版 (Jesse Liberty (著)、Brian MacDonald (著)、日向 俊二 (翻訳)、オライリージャパン)の11章(継承とポリモーフィズム)、11.9(練習問題)、問題11-1.を取り組んでみる。
コード
using System;
namespace Sample11_1
{
    class Telephone
    {
        protected string phonetype;
        public void Ring()
        {
            Console.WriteLine("Ring the {0}", phonetype);
        }
    }
    class ElectronicPhone : Telephone
    {
        public ElectronicPhone()
        {
            this.phonetype = "Digital";
        }
    }
    class Program
    {
        void Run()
        {
            ElectronicPhone ep = new ElectronicPhone();
            ep.Ring();
        }
        static void Main(string[] args)
        {
            Program p = new Program();
            p.Run();
        }
    }
}
入出力結果(Terminal)
Ring the Digital Press any key to continue...
 
0 コメント:
コメントを投稿