object Test {
def main(args: Array[String]): Unit = {
val man = new Man("zhangsan",18,180)
println(man)
}
}
class Man(name:String,age:Int){
var height:Int = _
def this(name:String,age:Int,height:Int){
this(name,age)
this.height = height
}
override def toString: String = {
s"普通人:${name}-${age}-${height}"
}
}
运行结果:
普通人:zhangsan-18-180