SCJP題庫第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
Comments