class inheritance
{
def a()
println("Version 1")
}
class inheritance1
{
def b()
println("version 2")
}
class inheritance2 extends inheritance
{
def c()
println("version 3")
}
class inheritance3 extends inheritance2
{
def d()
println("version 4")
}
object inherited
{
def main(args: Array[String])
{
var obj = new inheritance3
obj.d
obj.c
}
}
它引发了一些错误:
class inheritance needs to be abstract since method a is not defined
class inheritance1 needs to be abstract since method b is not defined
class inheritance2 needs to be abstract since it has two unimplemented members
class inheritance3 needs to be abstract since it has two unimplemented members
答案 0 :(得分:1)
像
这样的东西def a()
println("foo")
声明一个未定义的方法a
,它不接受任何参数并返回Nothing
然后打印出一个字符串。
def a() = println("foo")
或
def a() {
println("foo")
}
或
def a() =
println("foo")
定义方法a
,打印出一个字符串并返回Unit
。