- Kotlin Programming By Example
- Iyanu Adelekan
- 126字
- 2021-08-27 20:00:13
Properties
Classes can have properties that may be declared using the var and val keywords. For example, in the following code snippet, the Person class has three properties, age, firstName, and surname:
class Person { var age = 0
var firstName = ""
var surname = ""
}
Properties can be accessed through an instance of the class holding the property. This is done by appending a single dot character (.) to an instance identifier followed by the property name. For example, in the following code snippet, an instance—named person—of the Person class is created and its firstName, surname, and age properties are assigned by accessing the properties:
val person = Person()
person.firstName = "Raven"
person.surname = "Spacey"
person.age = 35
推薦閱讀
- The DevOps 2.3 Toolkit
- R語言數據分析從入門到精通
- Redis Applied Design Patterns
- AngularJS Web Application Development Blueprints
- Getting Started with SQL Server 2012 Cube Development
- The DevOps 2.4 Toolkit
- 實戰Java高并發程序設計(第3版)
- JavaScript:Moving to ES2015
- 焊接機器人系統操作、編程與維護
- Scala Reactive Programming
- 愛上micro:bit
- Django實戰:Python Web典型模塊與項目開發
- 軟件測試綜合技術
- Arduino可穿戴設備開發
- Moodle 3 Administration(Third Edition)