2013年2月11日月曜日

開発環境

『初めてのC# 第2版』(Jesse Liberty+Brian MacDonald著、日向俊二訳、オライリー・ジャパン、2006年、ISBN978-487312-194-7)の 第6章(オブジェクト指向プログラミング)6.8(練習問題)練習6-1.を解いてみる。

その他参考書籍

練習6-1.

コード

using System;

class Vehicle { }

class Car : Vehicle { }
class Truck : Vehicle { }
class Motorcycle : Vehicle { }
class Tester
{
    public void Run()
    {
    }
    static void Main()
    {
        Tester t = new Tester();
        t.Run();
    }
}

ちなみにJavaScriptの場合。

コード(BBEdit)

// JavaScriptではクラスではなくプロトタイプ継承を使う
var Vehicle = function () {},
    Car = function () {},
    Truck = function () {},
    Motorcycle = function( ) {};
Car.prototype = new Vehicle();
Truck.prototype = new Vehicle();
Motorcycle.prototype = new Vehicle();

pythonの場合。

コード(BBEdit)

sample.py

#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-

class Vehicle: pass
class Car(Vehicle): pass
class Truck(Vehicle):pass
class Motorcycle(Vehicle):pass

0 コメント:

コメントを投稿