SCJP 1.6版考題 076

出自 陳富國維基館
前往: 導覽搜尋
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.

解答


Ans: B

解說: new TestB()是產生TestB的物件,所以start方法為TestB的版本,答案是B