2017-08-16 6 views
1
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 
    } 
} 

それはいくつかのエラーがスローされます。スカラ継承:なぜ抽象クラスにクラスを定義する必要がありますか?

def a() 
println("foo") 

よう

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

メソッドを定義しますか? – Dima

+0

返信ありがとうございますが、正確であるようにしてください –

答えて

1

何かはパラメータや戻りNothingをとらず、その文字列を出力し、未定義のメソッドaを宣言します。

def a() = println("foo") 

又は

def a() { 
    println("foo") 
} 

又は

def a() = 
    println("foo") 

文字列を出力し、Unitを返すメソッドaを定義します。

+0

あなたの返信にDimaが大変感謝しますが、それでも同じエラーです –

+0

@ShellyVermaいいえ、そうではありません。 'class aheritance {def a()= println(" Version 1 ")}'エラーは発生しません。 – Dima

+0

ごめんなさいDimaがあなたに迷惑をかけていますが、コードを書き換えてもエラーは発生しません。ありがとうございました:)))) –

関連する問題