2010年11月13日土曜日

これは実質的に継承?

このエントリーをはてなブックマークに追加
package main

import "fmt"

type Base struct {
}

type Sub struct {
        Base
}

func (b Base) method() {
        fmt.Println("Call Base.method()")
}

func main() {
        b := Base{}
        b.method()
        s := Sub{}
        s.method()
}

結果は以下のとおり。

Call Base.method()
Call Base.method()

これは実質的に実装も継承しているということでOK?