官术网_书友最值得收藏!

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
主站蜘蛛池模板: 铜陵市| 英吉沙县| 丰县| 惠水县| 镇原县| 房山区| 岳普湖县| 长岛县| 三明市| 武平县| 顺平县| 万山特区| 绥江县| 八宿县| 子长县| 巩义市| 西乌珠穆沁旗| 章丘市| 右玉县| 长兴县| 沙田区| 景洪市| 监利县| 晋城| 南昌市| 隆昌县| 临漳县| 正阳县| 府谷县| 金坛市| 湖口县| 天全县| 新闻| 辽阳县| 都匀市| 安塞县| 温泉县| 蒙城县| 微山县| 青冈县| 鄢陵县|