为什么第一个gender打印出来的是null
我已经初试化了val gender: String = "male"
,但是貌似结果不对。
object ObjectExample { def main(args: Array[String]): Unit = { val student = new Student("zhu", 18, "zz") } class People(val name: String, val age: Int) { println("constructor") println(name) val gender: String = "male" println(gender) def this(name1: String) = { this("ci", 18) println("subconstructor") println(name) } } class Student(name: String, age: Int, val school: String) extends People(name, age){ println("derived constructor") println(name) println(school) override val gender: String = "female" println(gender) } }
constructor zhu null derived constructor zhu zz female
牧羊人nacy
相关分类