1、子类调用父类构造函数
import java.text.SimpleDateFormat
import java.util.{Calendar, Date}
class Employee(val name: String, val age: Int, val birth: String)
//子类需要使用父类的成员变量时是不需要使用val或var的,否则就会覆盖父类已定义的成员变量
class Sale(name: String, age: Int, birth: String, val dept: String, val sal: Double) extends Employee(name, age, birth) {
override def toString: String = "name:" + name + " age:"+ age + " birth:" + birth + " dept:" + dept + " sal:"+ sal
}
object TestEmployee{
def main(args: Array[String]): Unit = {
//准备日期及格式
val calc = Calendar.getInstance
val sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
//指定日期相减的字段
calc.add(Calendar.YEAR, -38)
//获取时间,getTime,用当前作为时间减去上面指定的year的值作为时间
val time = calc.getTime
//再调用SimpleDateFormat的format进行指定格式的转换
val ryan = new Sale("ryan", 22, sdf.fo