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