原创文章,转载请注明出处!

原文地址: http://www.ptbird.cn/2016/07/19/scala-chuji-demo-13/

There I am,in the world more exciting!

by postbird

www.ptbird.cn


13类的多重继承


 
package com.ptbird.scala /** * Created by postbird on 2016/5/25. * * 类的多重继承 */ class Human { println("human class ") } trait TTeacher extends Human { println("Teacher trait") def teach } trait PianoPlayer extends Human { println("Piano palyer trait") def playPiano = { println("I am playing piano") } } class PianoTeacher extends Human with TTeacher with PianoPlayer { println("piano teacher") override def teach = { println("i am teaching students") } } object ClassTest4 { def main(args: Array[String]): Unit = { // var pt=new PianoTeacher // human class // Teacher trait // Piano palyer trait // piano teacher var t2 = new Human with TTeacher with PianoPlayer { override def teach = { println("new human with tteacher pianoplayer") } } //匿名类 t2.teach // human class // Teacher trait // Piano palyer trait // new human with tteacher pianoplayer } }