标签:val main override scala tty obj abs extend dog
定义一个抽象类
abstract class Animal {
def walk(speed:Int)
def breathe() = {
println("animal breathes")
}
}
在具体Dog中 我们必须实现Animal实现的抽象方法
class Dog extends Animal {
override def walk (speed :Int) = {
println("dog walks, speed is " + speed)
}
}
object App {
def Main(args:Array[String]){
val d =new Dog(0
d.walk(10)
d.breathe()
}
运行结果:
dog walks, speed is 10
animal breathes
标签:val main override scala tty obj abs extend dog
原文地址:http://www.cnblogs.com/sjj1022/p/8012124.html