会输出什么? trait A { val audience: String println("Hello "+ audience) } class BMember(a: String = "World") extends A { val audience = a println("I repeat: Hello " + audience) } class BConstructor(val audience: String = "World") extends A { println("I repeat: Hello " + audience) } new BMember("Readers") new BConstructor("Readers")
解释:
When instantiating superclasses or traits, the parent constructor
can be visualized as being executed before the first line of the child
constructor but after the class definition.
class definition的意思就是class的声明(就是{ 之前的部分)
时间: 2024-11-05 13:30:30