6 kotlin之class
kotlin的class比Java更简洁面料采用,使用更方便,类似于方法直接写上参数即可
class Player {
var name: String = ""
constructor(fullName: String) {
this.name = fullName
}
fun sayHello() {
println("hello $name")
}
fun getAge(): Int {
return 18
}
}
class Match(private val home: String,
private val away: String, private val data: String) {
fun getMatchInfo(): String {
return "$away- $home -$data"
}
}
fun main() {
val player = Player("handsome")
player.sayHello()
println("${player.name} is ${player.getAge()}")
val math = Match("China", "building",
"20200522")
println(math.getMatchInfo())
}
image
喜欢可以加Q群号:874826112,一起学习,成长,交流工作经验,
记得要点赞,评论哦😯;
更多相关内容请点击主页查看,有你想不到的惊喜😂....
简书: https://www.jianshu.com/u/88db5f15770d
网友评论