当前位置: 技术问答>java相关
scjp问题.帮忙
来源: 互联网 发布时间:2015-04-03
本文导语: Giving the following class definitions 1. class BaseWidget extends Object { 2. String name = "BaseWidget"; 3. void speak() { System.out.println("I am "+name);} 4. } 5. class TypeAWidget extends BaseWidget { 6. TypeAWidget() { name = "TypeA";} 7. } Which...
Giving the following class definitions
1. class BaseWidget extends Object {
2. String name = "BaseWidget";
3. void speak() { System.out.println("I am "+name);}
4. }
5. class TypeAWidget extends BaseWidget {
6. TypeAWidget() { name = "TypeA";}
7. }
Which the following code fragments will compile and excute without error?
a. Object A = new BaseWidget();
A.speak;
b BaseWidget B = new TypeAWidget ();
B.speak;
c TypeAWidget C = new BaseWidget();
B.speak;
1. class BaseWidget extends Object {
2. String name = "BaseWidget";
3. void speak() { System.out.println("I am "+name);}
4. }
5. class TypeAWidget extends BaseWidget {
6. TypeAWidget() { name = "TypeA";}
7. }
Which the following code fragments will compile and excute without error?
a. Object A = new BaseWidget();
A.speak;
b BaseWidget B = new TypeAWidget ();
B.speak;
c TypeAWidget C = new BaseWidget();
B.speak;
|
Object 有speak()方法吗??