本文主要是创建了一个类,后续的很多例子都和本程序有关。
/**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
fun main() {
println("Hello, world!!!")
val p=Person()
p.name="Jack"
p.age=19
p.eat()
}
class Person{
var name=""
var age=0
fun eat(){
println(name+" is eating.He is "+age+" years old.")
}
}
运行结果:
Hello, world!!!
Jack is eating.He is 19 years old.