private:自己和伴生对象能访问
private[this]:只有自己能访问,伴生对象都不能访问
主构造器:例:class Student(var id:Int, val name:String, xx: String)
xx则默认为 private val xx
辅助构造器:不能写修饰符。例:
class Student private[this] ( var id: Int, val name: String) {
//id, name, age无修饰符
def this(id: Int,name: String, age: Int) = {
//第一句代码调用主构造器
this( id, name)
}
def this(id: Int,name: String, age: Int, xx:String) = {
//第一句代码调用辅助构造器
this( id, name, age)
}
}