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
fun main(args: Array<String>) { | |
val a = Test() | |
val b = Next() | |
a.hello("山田") | |
b.hello("鈴木") | |
}//main | |
open class Test(){ | |
fun hello(name : String){ | |
println("私は${name}です。HELLO!") |
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
fun main(args: Array<String>) { | |
val a = Test() | |
a.hello("山田") | |
}//main | |
class Test(){ | |
fun hello(name : String){ | |
println("私は${name}です。HELLO!") | |
}//hello | |
}//Test |
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
fun main(args: Array<String>) { | |
val a = Test(20) | |
}//main | |
class Test(var name : String, var age : Int){ | |
init{ | |
println("イニシャライザブロック内です。") | |
println("${name}です。${age}歳です。") | |
}//init | |
constructor(age: Int) : this("名無し", age){ |
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
fun main(args: Array<String>) { | |
val a = Test(20) | |
}//main | |
class Test(var name : String, var age : Int){ | |
init{ | |
println("イニシャライザブロック内です。") | |
println("${name}です。${age}歳です。") | |
}//init | |
constructor(age: Int) : this("名無し", age) //この行はセカンダリコンストラクタ |
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
fun main(args: Array<String>) { | |
val a = Test("山田", 20) | |
}//main | |
class Test(var name : String, var age : Int){ | |
init{ //ここからイニシャライザブロック | |
println("イニシャライザブロック内です。") | |
hello() | |
}//init //ここまでイニシャライザブロック | |
fun hello(){ |
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
fun main(args: Array<String>) { | |
val a = Test(age = 20, name ="山田") //名前と年齢 | |
val b = Test(name = "山田") //名前だけ | |
val c = Test(age = 20) //年齢だけ | |
a.hello() | |
b.hello() | |
c.hello() | |
}//main | |
class Test(var name : String var age : Int){ |
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
fun main(args: Array<String>) { | |
val a = Test(age = 20, name ="山田") //名前と年齢 | |
val b = Test(name = "山田") //名前だけ | |
val c = Test(age = 20) //年齢だけ | |
a.hello() | |
b.hello() | |
c.hello() | |
}//main | |
class Test(var name : String = "", var age : Int = 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
fun main(args: Array<String>) { | |
val a = Test(age = 20, name ="山田") //変数から書けば順番が逆でもエラーにならない | |
a.hello() | |
}//main | |
class Test(var name : String = "", var age : Int = 0){ | |
fun hello(){ | |
println("${name}です。${age}です。HELLO!") | |
}//hello | |
}//Test |
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
fun main(args: Array<String>) { | |
val a = Test("山田", 20) //ここのカッコに値をセットすると下のコンストラクタに値が入る | |
a.hello() | |
}//main | |
class Test(var name : String = "", var age : Int = 0){ //ここのカッコの中がコンスタラクタ | |
fun hello(){ | |
println("${name}です。${age}です。HELLO!") | |
}//hello | |
}//Test |
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
fun main(args: Array<String>) { | |
println("こんにちは") | |
println("さようなら") | |
print("こんばんは") | |
print("おやすみ") | |
} |
NewerOlder