Skip to content

OOP ​

クラス、継承、this、メソッドのオーバーライド。

yl
‡ 点 ⟦
    ⋔ init(x, y) ⟦
        this.x = x
        this.y = y
    ⟧
    ⋔ 長さ() ⟦
        ^ sqrt(this.x * this.x + this.y * this.y)
    ⟧
⟧

¤ p = ⇢ 点(3, 4)
» "長さ:", p.長さ()   ~ 5

継承 ​

yl
‡ 動物 ⟦
    ⋔ init(名前 :str) ⟦ this.名前 = 名前 ⟧
    ⋔ 鳴き声() ⟦ ^ "..." ⟧
⟧

‡ 犬 † 動物 ⟦
    ⋔ 鳴き声() ⟦ ^ "ワン!" ⟧
⟧

¤ ポチ = ⇢ 犬("ポチ")
» ポチ.名前 + " が言う: " + ポチ.鳴き声()

出力: ポチ が言う: ワン!

PHP で作られています。MIT ライセンス。