開発環境
- Microsoft Windows 7 Home Premium (OS)
- Microsoft Visual C# 2010 Express Edition (IDE)
- 言語: C#
『初めてのC# 第2版』(Jesse Liberty+Brian MacDonald著、日向俊二訳、オライリー・ジャパン、2006年、ISBN978-487311-294-7)の 第6章(オブジェクト指向プログラミング)6.8(練習問題)、練習6-2を解いてみる。
練習6-2.
コード
using System;
class Book
{
private string title;
private string author;
double isbn;
public Book(string title, string author, double isbn)
{
this.title = title;
this.author = author;
this.isbn = isbn;
}
public void Read()
{
Console.WriteLine("本({0})を読む。", this.title);
}
public void Shelved()
{
Console.WriteLine("本({0})を書棚に保管する。", this.title);
}
}
class Tester
{
public void Run()
{
string title = "Kamimura's blog";
string author = "kamimura";
double isbn = 123456789;
Book blog = new Book(title, author, isbn);
blog.Read();
blog.Shelved();
}
static void Main()
{
Tester t = new Tester();
t.Run();
}
}
入出力結果(Console Window)
本(Kamimura's blog)を読む。 本(Kamimura's blog)を書棚に保管する。 続行するには何かキーを押してください . . .
0 コメント:
コメントを投稿