1.简单类和无参方法
class Demo { private var value = 0 def increment(): Unit = { value += 1 } def current = value } object Test { def main(args: Array[String]): Unit = { //创建对象 val demo = new Demo() //或者是Demo() demo.increment() //取值不加() 改值添加() val result = demo.current //定义函数没有加() 时,不能加() println(result) } }
2.带getter/setter属性
3.只带getter属性
4.对象私有属性
5.bean属性
6.辅助构造器
7.主构造器
8.嵌套类
原文:https://www.cnblogs.com/yin-fei/p/10827657.html