伴生对象:与类名相同并且用Object修饰的对象, 类和伴生对象可以互相访问私有方法和属性
package day03 class Dog { private var name = "dog" def printName() : Unit = { println(Dog.CONSTANT + name) } } object Dog { private val CONSTANT = "wolf, wolf, wolf" def main(args: Array[String]): Unit = { val p = new Dog // 访问类中私有字段 println(p.name) p.name = "big huang" p.printName() } }