新建一个 Person 类,简单声明两个成员变量和一个方法。
package com.cosmos.helloworld
class Person {
var name = ""
var id = 0
fun work(){
println("$name is working. He's id is $id")
}
}
在 main() 函数中实例化并进行一些操作,
package com.cosmos.helloworld
fun main(){
var p = Person()
p.name = "Brown"
p.id = 2021
p.work()
}
运行结果,
Brown is working. He's id is 2021
参照 Kotlin笔记1–用AS运行Kotlin代码,打印Hello Kotlin_南国樗里疾的博客-CSDN博客
https://blog.csdn.net/weixin_44021334/article/details/117672446
当前目录结构,