类定义
class ChecksumAccumulator { }
类属性字段,属性默认为public
class ChecksumAccumulator { var sum = 0 }
类 方法
class ChecksumAccumulator {
private var sum = 0
def add(b: Byte): Unit = {
sum += b
}
def checksum(): Int = {
return ~(sum & 0xFF) + 1
}
}
类 单例对象
object Person { }