開発環境
- Microsoft Windows 8 Pro 64bit 日本語 (OS)
- Microsoft Visual Studio Express 2012 for Windows Desktop (IDE)
- プログラミング言語: C#
『初めてのC# 第2版』(Jesse Liberty+Brian MacDonald著、日向俊二訳、オライリー・ジャパン、2006年、ISBN978-487311-294-7)の 第6章(オブジェクト指向プログラミング)6.8(練習問題)問題6-1を解いてみる。
その他参考書籍
問題6-1.
コード
using System; class Vehicla { } class Car : Vehicla { } class Truck : Vehicla { } class Motorcycle : Vehicla { } class Tester { public void Run() { } static void Main() { Tester t = new Tester(); t.Run(); } }
ちなみにJavaScriptの場合。
コード(BBEdit)
var Vehicle = function(){}; var Car = function(){ Vehicle.apply(this); }; Car.prototype = new Vehicle(); var Truck = function(){ Vehicle.apply(this); }; Truck.prototype = new Vehicle(); var Motorcycle = function(){ Vehicle.apply(this); }; Motorcycle.prototype = new Vehicle();
pythonの場合。
sample.py
コード(BBEdit)
#!/usr/bin/env python3.3 # -*- coding: utf-8 -*- class Vehicle:pass class Car(Vehicle):pass class Truck(Vehicle):pass class Motorcycle(Vehicle):pass
0 コメント:
コメントを投稿