2017-05-12 2 views
0

私は講義から次の質問を受けて、回答がiii.It compiles, runs and prints the string “Hello”だと答えましたが、回答はi. It has a compilation errorだと信じています。輸入packA.AまたはpackAする必要があります* 私の質問をされて - 。これはタイプミスであるか、これはまだクラスを指定しないインポートパッケージ

J. Assuming the class A and class B given below are defined in different packages, packA and packB. 

    package packA; 
    public class A { 
     protected void msg() { 
      System.out.println("Hello"); 
     } 
    } 

    package packB; 
    import packA; 
    class B extends A { 
     public static void main(String[] args) { 
      B obj = new B(); 
      obj.msg(); 
     } 
    } 


    which of the following is correct about the class B? 

    i. It has a compilation error 
    ii. It has a run time error 
    iii.It compiles, runs and prints the string “Hello” 
    iv. None of the above 
+2

TRY IT YOURSELF。 –

+1

なぜ叫び声ですか?!?!?!?!?!?!?!?!?!?! – Turing85

+0

私はそれを試してみましたが、 "import packA.A"または "import packA。*"をクラスBに指定しない限り、プログラムを実行することはできませんが、これが絶対に正しいかどうかはまだ分かりません。私は静かではないここにキャッチしていますか?または、おそらく私は正しいとこれは実際にはタイプミスですか? –

答えて

0

実際の輸入に誤りがあり、「こんにちは」を実行し、印刷することができます。それはimport packA.A;でなければなりません。

+0

に感謝します。それについて何が間違っていますか? – VincentN

+0

コードに間違いがありますが、輸入はpackA.A – VincentN

+0

でなければなりませんが、それに感謝していただきありがとうございます。 –

関連する問題