Created
February 17, 2013 17:08
-
-
Save ozw-sei/4972316 to your computer and use it in GitHub Desktop.
Scala勉強中@コップ本 クラス ref: http://qiita.com/items/65760454415aba9c1e94
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 SampleClass{ | |
//何も書かないとpublic参照 | |
var num =0 | |
} |
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
//インスタンス生成 | |
val tmp = new SampleClass | |
//値変更 | |
tmp.num = 1 | |
//valなので、最代入できません。 | |
tmp = new SampleClass | |
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 Vector2 { | |
private var x:Int | |
private var y:Int | |
} | |
//インスタンス生成 | |
val pos = new Vector2 | |
pos.x //アクセスエラー | |
pos.y //アクセスエラー |
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
//シングル | |
object test{ | |
def disp() = print("Hello,World") | |
} | |
//オブジェクト名から呼び出し | |
test.disp() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment