求教一道模拟题?
Given the following class definitions:
1. class BaseWidget extends Object{
2. String name="BaseWidget";
3. void speak(){System.out.println("I am a "+name);}
4. }
5. class TypeAWidget extends BaseWidget{
6. TypeAWidget(){name="TypeA";}
7. }
Which of the following code fragments will compile and execute without error?
a. Object A=new BaseWidget();
A.speak();
b. BaseWidget B=new TypeAWidget();
B.speak();
c. TypeAWidget C=new BaseWidget();
C.speak();
答案为b.
请问:a 为什么不对???