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

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

There I am,in the world more exciting!

by postbird

www.ptbird.cn


11抽象类


 
package com.ptbird.scala /** * Created by postbird on 2016/5/25. */ abstract class SuperTeacher(val name: String) { var id: Int var age: Int def teach } class TeacherForMaths(name: String) extends SuperTeacher(name) { override var id = name.hashCode() override var age = 29 override def teach: Unit = { println("Teaching Math" + this.age + "--" + this.id) } } object ClassTestAb { def main(args: Array[String]): Unit = { val teacher = new TeacherForMaths("ptbird") teacher.teach } //Teaching Math29---978349891 }