14.现有:
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行,有几个可以通过编泽? A. 1 B. 2 C. 3 D. 4
15.现有:
1. class HorseRadish { 2. //insert code here
3.protected HorseRadish (int x) { 4.System.out.println (\ 5. } 6. }
7. class Wasabi extends HorseRadish {
8.public static void main (String [] args) ( 9.Wasabi w- new Wasabi(); 10, } 11. }
分别插入到第2行,哪两项允许代码编译并产生”bok choy”输出结果?(选
两项)
A. protected HorseRadish() {this (42);} B. protected HorseRadish() {} C. //just a comment
D. protected HorseRadish() { new HorseRadish (42);}
1-31
参考答案
.
1ABD 2B 3C 4D SB 6A 7D 8D 9C 10 A 11 D 12 D 13 C 14 D 15 AD
1-32
第六章练习题(抽象类与接口)
1.下列有关抽象类的叙述正确的是哪项? A.抽象类中一定含有抽象方法
B.抽象类的声明必须包含abstract关键字 C.抽象类既能被实例化也能被继承 D.抽象类中不能有构造方法
2.下列有关抽象方法叙述正确的是哪项?(选两项)
A. 抽象方法和普通方法一样,只是前面多加一个修饰符asbtract B.抽象方法没有方法体
c.抽象方法可以包含存任何类中
D.包含抽象方法的类的具体子类必须提供具体的覆盖方法
3.下列有关接口的叙述错误的是哪项? A.接口中只能包含抽象方法和常量 B.一个类可以实现多个接口
C.类实现接口时必须实现其中的方法 D.接口不能被继承
4.下列关于接口的定义哪项是正确的? A. interface C{int a;)
B. public interface A implements B {) C. public interface A {int a(); ) D. abstract interface D {)
1-33
5.现有:
1. interface Animal f 2. void eat(); 3. } 4.
5. // insert code here 6.
7. public class HouseCat implements Feline { 8. public void eat() { } 9. }
和以下三个接口声明:
interface Feline extends Animal ( )
interface Feline extends Animal {void eat(); }
interface Feline extends Animal {void eat() { } } 分别插入到第5行,有多少行可以编译? A. 0 B. 1 C. 2 D. 3
6.现自:
1. interface Color { } 2. interface Weight { } 3. //insert code here 和以下足六个声明:
class Boat extends Color, extends Weight { } class Boat extends Color and Weight { } class Boat extends Color, Weight { }
class Boat implements Color, implements Weight { } class Boat implements Color and Weight { } class Boat implements Color, Weight { } 分别插入到第3行,有多少行可以编译? A. 0 B. 1 C. 2 D. 3
1-34
7.现有:
1. abstract class Color {
2.protected abstract String getRGB(); 3. } 4.
5. public class Blue extends Color { 6. //insert code here 7. }
和四个声明:
public String getRGB() { return \ } String getRGB() { return \ )
private String getRGB() { return \ } protected String getRGB() { return \ ) 分别插入到第6行,有几个可以通过编译? A. 0 B. 1 C. 2 D. 3
8.现有:
1. abstract class Color2 { 2. //insert code here 3. } 4.
5. public class Blue2 extends Color2 {
6.public String getRGB() { return \ } 7. }
和4个声明:
public abstract String getRGB(); abstract String getRGB();
private abstract String getRGB(); protected abstract String getRGB();
分别插入到第2行,有多少行可以编译? A. O B. 1 C. 2 D 3
1-35