-
-
Save mistyrinth/564dbb94b3c8927d99eaec0c154fb84f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 親クラスとメソッドの定義 | |
class Car | |
def accele | |
print("アクセルを踏みました\n") | |
end | |
def brake | |
print("ブレーキを踏みました\n") | |
end | |
end | |
# 子クラスへの継承 | |
class Soarer < Car | |
# メソッドのオーバーライド | |
def accele | |
# 親クラスの同名メソッド(accele)呼び出し | |
super | |
print("加速しました\n") | |
end | |
end | |
soarer = Soarer.new | |
soarer.accele |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment