package com.test.scala.test /** * 模拟java的继承,扩展类 */ abstract class ExtendClass(val des:String) { def undo():String def redo():String } object DoNothingAction extends ExtendClass("do nothing"){ override def undo:String={"I don't know how!"} override def redo:String={"aaa"} } object test{ def main(args: Array[String]): Unit = { val actions=Map("hello"->DoNothingAction,"go"->DoNothingAction); for((k,v)<-actions)println(k+"->"+v.redo()) } }
package com.test.scala.test /** * 继承类学习 */ class ExtendClassStudent { final def add(a:Int,b:Int):Int={a+b} def aa(bb:String):String={bb} } class Zilei extends ExtendClassStudent{ override def aa(bb:String):String={bb} }