trait基本使用

29 阅读1分钟

特质

trait: 实现多继承
1: 具体属性,抽象属性
2: 具体方法,抽象方法

问: 怎么区分具体属性和抽象属性?

有具体值的,就是具体属性。看看有没有“ = ”

case object class11 {

    trait  BeautifulEye {
      val eye:String = "眼睛漂亮"
    }

trait  Tall {
 val height:String = "大高个"
}

// 继承  with
class Child extends  BeautifulEye with  Tall{

}
def main(args: Array[String]): Unit = {
 val child = new Child()
 println(child.eye)
 println(child.height)