8. public static void main(String [] args) { 9. SubCat s = new SubCat(); 10. } 11. }
结果为:(D) A. cat5 B.cable C.cable cat5 D.cat5 cable
E.编译失败
运行时异常被抛出 92. 现有:
1. class Guy { String greet() { return “hi “; } }
2. class Cowboy extends Guy { String greet() { return “howdy “; } } 3. class Surfer extends Guy { String greet() { return “dude! “; } } 4.
5. class Greetings {
6. public static void main(String [] args) {
7. Guy [] guys = { new Guy(), new Cowboy(), new Surfer() }; 8. for(Guy g : guys)
9. System.out.print(g.greet()); 10. } 11. }
结果为:(B) A. hi hi hi
B.hi howdy dude!
C.运行时异常被抛出。
D.第 7 行出现一个错误,编译失败。 E.第 8 行出现一个错误,编译失败。 93. 现有:
12. class Super { 13. protected int a;
14. protected Super(int a) { 15. System.out.print(this.a); this.a = a; } 16. }
17. class Sub extends Super {
18. public Sub(int b) { super(b); a = super.a;} 19. public static void main(String [] args) { 20. new Sub(7).go(); 21. }
22. void go() { System.out.print(this.a); } 23. }
结果为:(B) A. 00 B.07 C.70 D.77 ;编译失败
;运行时异常被抛出 94. 现有:
1. class Animal { Animal getOne() { return new Animal(); } } 2. class Dog extends Animal { 3. // insert code here 4. } 5.
6. class AnimalTest {
7. public static void main(String [] args) {
8. Animal [] animal = { new Animal(), new Dog() } ; 9. for( Animal a : animal) { 10. Animal x = a.getOne(); 11. } 12. } 13. }
和代码:
3a. Dog getOne() { return new Dog(); } 3b. Animal getOne() { return new Dog(); }
第 3 行中插入的哪项将编译且运行无异常?(C) A. 3a 行 B.3b 行
C.3a 行或 3b 行 D.既非 3a,也非 3b 95现有:
5. class BitStuff {
6. BitStuff go() { System.out.print(“bits “); return this; } 7. }
8. class MoreBits extends BitStuff {
9. MoreBits go() { System.out.print(“more “); return this; } 10.
11. public static void main(String [] args) {
12. BitStuff [] bs = {new BitStuff(), new MoreBits()}; 13. for( BitStuff b : bs) 14. b.go(); 15. }
16. }
结果为:(B)
A. bits bits B. ;bits more C. ;more more D. ;编译失败
E. ;运行时异常被抛出
96现有:
1. class SuperFoo {
2. SuperFoo doStuff(int x) { 3. return new SuperFoo(); 4. } 5. } 6.
7. class Foo extends SuperFoo { 8. // insert code here 9. }
和四个声明:
Foo doStuff(int x) { return new Foo(); }
Foo doStuff(int x) { return new SuperFoo(); } SuperFoo doStuff(int x) { return new Foo(); } SuperFoo doStuff(int y) { return new SuperFoo(); }
分别插入到第8行,有几个可以通过编译?(D) 0 A.1 B.2 C.3 D.4
97.c lass Bird {
2. void talk() { System.out.print(“chirp “); } 3. }
4. class Parrot2 extends Bird {
5. protected void talk() { System.out.print(“hello “); } 6. public static void main(String [] args) {
7. Bird [] birds = {new Bird(), new Parrot2()}; 8. for( Bird b : birds) 9. b.talk(); 10. } 11. }
结果是什么?(B)
A. chirp chirp
B.chirp hello C.hello hello D.编译失败
E.运行的时候有异常抛出
98. 现有:
1. class Beverage {
2. Beverage() { System.out.print(“beverage “); } 3. }
4. class Beer extends Beverage {
5. public static void main(String [] args) { 6. Beer b = new Beer(14); 7. }
8. public int Beer(int x) { 9. this();
10. System.out.print(“beer1 “); 11. }
12. public Beer() { System.out.print(“beer2 “); } 13. }
结果是什么?(E)
A. beer1 beverage B.beer2 beverage C.beverage beer1
D.beverage beer2 beer1 E.编译失败
F.运行的时候有异常抛出
99. 现有: 1. class Dog { }
2. class Harrier extends Dog { } 3.
4. class DogTest {
5. public static void main(String [] args) { 6. Dog d1 = new Dog();
7. Harrier h1 = new Harrier(); 8. Dog d2 = h1;
9. Harrier h2 = (Harrier) d2; 10. Harrier h3 = (Harrier) d1; 11. } 12. }
哪一个是对的?(B)
A. 编译失败
B.运行的时候有异常抛出 C.创建了两个 Dog 对象
D.创建了两个 Harrier 对象 E.创建了三个 Harrier 对象
100. 现有:
1. class Guy { String greet() { return “hi “; } }
2. class Cowboy extends Guy { String greet() { return “howdy “; } } 3. class Wrangler extends Cowboy { String greet() { return “ouch! “; } } 4.
5. class Greetings2 {
6. public static void main(String [] args) { 7. Guy g = new Wrangler(); 8. Guy g2 = new Cowboy();
9. Wrangler w2 = new Wrangler();
10. System.out.print(g.greet()+g2.greet()+w2.greet()); 11. } 12. } 结果是什么?(C)
A. hi hi ouch! B.hi howdy ouch! C.ouch! howdy ouch!
D.编译失败
;运行的时候有异常抛出
101. 现有: 2. class Cat {
3. Cat(int c) { System.out.print(“cat“ + c + “ “); } 4. }
5. class SubCat extends Cat {
6. SubCat(int c) { super(5); System.out.print(“cable “); } 7. SubCat() { }
8. public static void main(String [] args) { 9. SubCat s = new SubCat(); 10. } 11. }
结果是什么?(E)
A. cat5 B.cable C.cable cat5 D.cat5 cable E.编译失败
;运行的时候有异常抛出
102. 现有:
1. class Over {
2. int doIt(long x) { return 3; } 3. } 4.
5. class Under extends Over { 6. // insert code here 7. }
和四个方法:
short doIt(int y) { return 4; } int doIt(long x, long y) { return 4; } private int doIt(short y) { return 4; } protected int doIt(long x) { return 4; }
分别插入到第6行,有几个可以通过编译?(E)
A. 0 B.1 C.2 D.3 ;4
103. 类:
class TestApp{ static{
System.out.print(2); }
public TestApp(){
System.out.print(1); } }
当执行new TestApp()后程序的输出是哪项?(E)
A. 1 B.12 C.22 D.2 E.21
104. 下列有关抽象类的叙述正确的是哪项?(D)
A. 抽象类中一定含有抽象方法 B.抽象类中不能有构造方法
C.抽象类既能被实例化也能被继承
D.抽象类的声明必须包含abstract关键字 105. 下列有关接口的叙述错误的是哪项?(C)
A. 接口中只能包含抽象方法和常量 B.一个类可以实现多个接口 C.接口不能被继承
D.类实现接口时必须实现其中的方法
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库Java习题(7)在线全文阅读。
相关推荐: