Question 19 : 클래스의 형변환
Given:
1. class TestA {
2. public void start() { System.out.println(”TestA”); }
3. }
4. public class TestB extends TestA {
5. public void start() { System.out.println(”TestB”); }
6. public static void main(String[] args) {
7. ((TestA)new TestB()).start();
8. }
9. }
What is the result?
A. TestA
B. TestB
C. Compilation fails.
D. An exception is thrown at runtime.
Answer: B
Given:
1. class TestA {
2. public void start() { System.out.println(”TestA”); }
3. }
4. public class TestB extends TestA {
5. public void start() { System.out.println(”TestB”); }
6. public static void main(String[] args) {
7. ((TestA)new TestB()).start();
8. }
9. }
What is the result?
A. TestA
B. TestB
C. Compilation fails.
D. An exception is thrown at runtime.
Answer: B
반응형
'잘난놈되기 > SCJP' 카테고리의 다른 글
Q021. 추상클래스 (1) | 2008.05.03 |
---|---|
Q020. 내부 무명 클래스 (0) | 2008.04.30 |
Q018. 인터페이스 (0) | 2008.04.13 |
Q017. import static (0) | 2008.04.11 |
Q016. 내부클래스 (0) | 2008.04.04 |