2018年4月28日土曜日

開発環境

初めてのC# 第2版 (Jesse Liberty (著)、Brian MacDonald (著)日向 俊二 (翻訳)、オライリージャパン)の11章(継承とポリモーフィズム)、11.9(練習問題)、練習11-1.を取り組んでみる。

コード

using System;

class Program
{
    public void Run()
    {
        ElectronicPhone ep = new ElectronicPhone();
        ep.Ring();
    }
    static void Main(string[] args)
    {
        Program p = new Program();
        p.Run();
    }
}

class Telephone
{
    protected string phonetype = "Telephone";

    public void Ring()
    {
        Console.WriteLine("Ring the " + phonetype);
    }
}

class ElectronicPhone:Telephone
{
    public ElectronicPhone()
    {
        this.phonetype = "Digital"; 
    }
}

入出力結果(コマンドプロンプト)

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

0 コメント:

コメントを投稿