当前位置:网站首页>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()
}
边栏推荐
- BCG 使用之CBCGPProgressDlgCtrl进度条使用
- kotlin 继承
- 1007 maximum subsequence sum (25 points) (PAT class a)
- 项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
- MySQL数据库基本操作-DDL | 黑马程序员
- BCG 使用之CBCGPTabWnd控件(相当于MFC TabControl)
- Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
- 1002. A+B for Polynomials (25)(PAT甲级)
- Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
- C语言-入门-基础-语法-流程控制(七)
猜你喜欢
线上数据库迁移的几种方法
勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
JVM系列之对象的创建
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
Lm10 cosine wave homeopathic grid strategy
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
The 300th weekly match of leetcode (20220703)
记一次 .NET 某工控数据采集平台 线程数 爆高分析
Pytorch学习(四)
92.(cesium篇)cesium楼栋分层
随机推荐
Pointnet/Pointnet++点云数据集处理并训练
How to use async Awati asynchronous task processing instead of backgroundworker?
Jetpack compose tutorial
BCG 使用之CBCGPProgressDlgCtrl進度條使用
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
Add namespace declaration
[QNX Hypervisor 2.2用户手册]6.3.1 工厂页和控制页
牛客小白月赛7 I 新建 Microsoft Office Word 文档
Multi table operation - external connection query
1006 Sign In and Sign Out(25 分)(PAT甲级)
FPGA时序约束分享01_四大步骤简述
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
求2的n次方
C # use stopwatch to measure the running time of the program
“只跑一趟”,小区装维任务主动推荐探索
测试工程师如何“攻城”(下)
ftp、sftp文件传输
HDU 6440 2018 Chinese college student program design network competition
Educational codeforces round 22 E. Army Creation
To sort out messy header files, I use include what you use