[英]import package without specifying class
在我的演講中,我得到了以下問題,並告訴他答案是iii.It compiles, runs and prints the string “Hello”
但是我相信答案是i. It has a compilation error
i. It has a compilation error
這是由於B類導入packA的方式不正確,而應該是import packA.A或packA。*我的問題是-這是拼寫錯誤還是可以繼續運行並打印“ Hello”
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
導入確實存在錯誤。 應該是import packA.A;
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.