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

Working with classes

A class is declared using the class keyword followed by the class name:

class Person

As in the preceding example, a class in Kotlin need not have a body. Though this is charming, almost all the time you will want your class to have characteristics and behaviors placed within a body. This can be done with the use of opening and closing brackets:

class HelloPrinter {
fun printHello() {
println("Hello!")
}
}

In the preceding code snippet, we have a class named HelloPrinter with a single function declared in it. A function that is declared within a class is called a method. Methods can also be referred to as behaviors. Once a method is declared, it can be used by all instances of the class.

主站蜘蛛池模板: 南丹县| 新河县| 峨山| 同江市| 南汇区| 颍上县| 阿鲁科尔沁旗| 普定县| 普宁市| 昭觉县| 南京市| 拜城县| 潼南县| 济宁市| 都安| 淮滨县| 嘉义市| 荣成市| 沙雅县| 云和县| 恩施市| 若羌县| 阳西县| 黄石市| 抚松县| 景东| 怀宁县| 舞钢市| 兴安县| 酒泉市| 新营市| 霍林郭勒市| 水富县| 镇坪县| 东乌| 永年县| 赤城县| 舟曲县| 眉山市| 冕宁县| 迭部县|