trait基本使用

25 阅读1分钟
/* 
* 特质 
*
trait:实现多继承
* */ object class15 {
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) 
} 
}