티스토리 뷰

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로 변환할 수 없다.

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함