当前位置:网站首页>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()
}
边栏推荐
- Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
- 1011 World Cup betting (20 points) (pat a)
- 1007 maximum subsequence sum (25 points) (PAT class a)
- kotlin 基本使用
- 1009 product of polynomials (25 points) (PAT class a)
- 牛客小白月赛7 E Applese的超能力
- 明明的随机数
- 1011 World Cup Betting (20 分)(PAT甲级)
- Hough transform Hough transform principle
- Cbcgpprogressdlgctrl progress bar used by BCG
猜你喜欢

Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading

联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点

Opencv functions and methods related to binary threshold processing are summarized for comparison and use

"Only one trip", active recommendation and exploration of community installation and maintenance tasks

C# 使用StopWatch测量程序运行时间

FPGA时序约束分享01_四大步骤简述

mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总

Pointnet/Pointnet++点云数据集处理并训练

Hough Transform 霍夫变换原理

勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
随机推荐
Wechat reading notes of "work, consumerism and the new poor"
偏移量函数及开窗函数
Matrix flip (array simulation)
1008 Elevator(20 分)(PAT甲级)
BCG 使用之CBCGPProgressDlg进度条使用
做社交媒体营销应该注意些什么?Shopline卖家的成功秘笈在这里!
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
C语言-入门-基础-语法-流程控制(七)
矩阵翻转(数组模拟)
Shell programming core technology "four"
Shell programming core technology "three"
Utilisation de la barre de progression cbcggprogressdlgctrl utilisée par BCG
在线SQL转Excel(xls/xlsx)工具
PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
Online text line fixed length fill tool
@transactional滥用导致数据源连接池耗尽问题
BCG 使用之CBCGPProgressDlgCtrl进度条使用
HDU 6440 2018 Chinese college student program design network competition
kotlin 基本数据类型
黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例