当前位置:网站首页>Kotlin classes and objects
Kotlin classes and objects
2022-07-04 19:41:00 【AdleyTales】
import java.util.*
// Class contains constructors 、 Initialize code block 、 function 、 attribute 、 Inner class 、 Object declaration
// Non empty properties must be initialized at the time of definition ,kotlin Provides a way to delay initialization , Use lateinit Keyword description properties
class People {
// The properties of a class can use keywords var Declare variable , Otherwise, use read-only keywords val Declared immutable
var name: String = ""
var age: Int = 0
var addr: String = ""
get() = field.uppercase()
set(value) {
field = "G+$value"
}
constructor(name: String, age: Int, addr: String) {
this.name = name
this.age = age
this.addr = addr
println("constructor------")
}
constructor(name: String, age: Int) {
this.name = name
this.age = age
}
init {
println("init ------")
}
// Member functions
fun foo() {
println("foo ---")
}
fun info() {
println("name: $name, age: $age, addr: $addr")
}
}
fun main() {
val p = People("adleytales", 19, "Beijing")
p.foo()
p.info()
p.name = "adley"
p.age = 18
p.info()
}
边栏推荐
- How to use async Awati asynchronous task processing instead of backgroundworker?
- Master the use of auto analyze in data warehouse
- "Only one trip", active recommendation and exploration of community installation and maintenance tasks
- Shell programming core technology "I"
- PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
- kotlin 类和对象
- Detailed explanation of the binary processing function threshold() of opencv
- Educational Codeforces Round 22 E. Army Creation
- The kth largest element in the array
- Jetpack Compose 教程
猜你喜欢
Pytorch学习(四)
升级智能开关,“零火版”、“单火”接线方式差异有多大?
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
Oracle with as ORA-00903: invalid table name 多表报错
abc229 总结(区间最长连续字符 图的联通分量计数)
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
Stream流
Siemens HMI download prompts lack of panel image solution
C# 使用StopWatch测量程序运行时间
随机推荐
Jetpack compose tutorial
牛客小白月赛7 I 新建 Microsoft Office Word 文档
HDU 1097 A hard puzzle
牛客小白月赛7 F题
求2的n次方
Shell programming core technology II
牛客小白月赛7 谁是神箭手
Double colon function operator and namespace explanation
Educational Codeforces Round 22 E. Army Creation
矩阵翻转(数组模拟)
TCP waves twice, have you seen it? What about four handshakes?
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
TCP两次挥手,你见过吗?那四次握手呢?
Online sql to excel (xls/xlsx) tool
1005 Spell It Right(20 分)(PAT甲级)
C语言-入门-基础-语法-流程控制(七)
kotlin 类和对象
Niuke Xiaobai month race 7 F question
Explicit random number
Master the use of auto analyze in data warehouse