나는 강의에서 다음 질문을 받았으며 그 대답은 iii.It compiles, runs and prints the string “Hello”
이라고 대답했지만 대답은 i. It has a compilation error
이라고 생각합니다. 이는 클래스 B 가져 오기 packA가 올바르지 않고 대신 수입 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
자신을 생각해보십시오. –
이유는 무엇입니까?!?!?!?!?!?!?!?!? – Turing85
"import packA.A"또는 "import packA. *"를 클래스 B에 지정하지 않으면 프로그램을 실행할 수 없지만 이것이 절대적으로 정확한지 확실하지 않습니다. 내 강사가 뭔가 다른 것을 의미 할 수도 있습니다. 나는 여기 잡는 게 조용하지 않니? 또는 어쩌면 나는 옳고 이것이 실제로 오타입니까? –