ocajp 자격증 (Oracle Certified Associate Ja
ocjap 문제 해설 - extends 76
xemaker
2020. 3. 2. 20:38
class C2 {
public void displayC2() {
System.out.print("C2");
}
}
interface I {
public void displayI();
}
class C1 extends C2 implements I {
public void displayI() {
System.out.print("C1");
}
}
public class Extend76 {
public static void main(String[] args) {
C2 obj1=new C1();
I obj2=new C1();
C2 s = obj2;
I t=obj1;
t.displayI();
s.displayC2();
}
}
What is the result?
A. C2C2
B. C1C2
C. C1C1
D. Compilation fails
정답: D
해설:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Type mismatch: cannot convert from I to C2
Type mismatch: cannot convert from C2 to I
at Extend76.main(Extend76.java:22)
C2 s = obj2;
I t=obj1;
이 두 부분에서 컴파일 에러가 발생한다.
C2 s = obj2;
-> Type mismatch: cannot convert from C2 to I
C2를 I로 변환할 수 없다.
I t=obj1;
-> Type mismatch: cannot convert from I to C2
I를 C2로 변환할 수 없다.