class Car(val produce:String,val model:String,val modelYear:Int,carNum:String) {
def this(produce:String,model:String){
this(produce,model,-1,“”)
}
def this (produce:String,model:String,modelYear:Int){
this (produce,model,modelYear,“”)
}
def this (produce:String,model:String,carNum:String){
this (produce,model,-1,carNum)
}
def printAll(): Unit ={
println(“制造商:”+produce+" 型号名称:“+model
+” 型号年份:“+modelYear+” 车牌号:"+carNum)
}
}
object Car5{
def main(args: Array[String]): Unit = {
var car1=new Car(“RW”,“RX5”)
car1.printAll()
var car2=new Car(“RW”,“RX5”,2018)
car2.printAll()
var car3=new Car(“RW”,“RX5”,“A001”)
car3.printAll()
var car4=new Car(“RW”,“RX5”,2018,“A001”)
car4.printAll()
}
}