java第二次小测试

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Given:

1. public class Base{

2. public static final String FOO = "foo";

3. public static void main(String[] args){

4. Base b = new Base();

5. Sub s = new Sub();

6. System.out.print(Base.FOO);

7. System.out.print(Sub.FOO);

8. System.out.print(b.FOO);

9. System.out.print(s.FOO);

10. System.out.print(((Base)s).FOO); //S变为父类,调用父类的函数

11. }

12. }

13. class Sub extends Base{public static final String FOO = "bar";} //子类特有,与父类相同,把父类隐藏

What is the result?

A. foofoofoofoofoo

B. foobarfoobarbar

C. foobarfoofoofoo

D. foobarfoobarfoo

E. barbarbarbarbar

F. foofoofoobarbar

G. foofoofoobarfoo

第32題ABCF

Given:

1. class Mammal{}

2.

3. class Raccoon extends Mammal

4. Mammal m = new Mammal();

5. }

6.

7. class BabyRaccoon extends Mammal{}

Which four statments are true? (Choose four.)

A. Raccoon is-a Mammal.

B. Raccoon has-a Mammal.

C. BabyRaccoon is-a Mammal.

D. BabyRaccoon is-a Raccoon.

E. BabyRaccoon has-a Mammal.

F. BabyRaccoon is-a BabyRaccoon.

Given: //方法重写修饰符不能更私有

2. public class Hi{

3. void m1(){}

4. protected void m2(){}

5. }

6. class Lois extends Hi{

7. //insert code here

8. }

Which four code fragments, inserted independently at line 7, will compile? (Choose four.)

A. public void m1(){}

B. protected void m1(){}

C. private void m1(){}

D. void m2(){}

E. pubic void m2(){}

F. protected void m2(){}

G. private void m2(){}

第34題ACDG

Which four statements are true? (Choose four.)

A. Has-a relationships should never be encapsulated(封装).

B. Has-a relationships should be implemented using inheritance.

C. Has-a relationships can be implemented using instance variables.

D. Is-a relationships can be implemented using the extends keyword.

E. Is-a relationships can be implemented using the implements (继承)keyword.

F. The relationship between Movie and Actress is an example of an is-a relationship.

G. An array or a collection can be used to implement a one-to-many has-a relationship.

第35題 E

Given:

10. public class Hello{

11. String title;

12. int value;

13. public Hello(){ //构造器

14. title += " World";

15. }

16. public Hello(int value){

17. this.value = value;

18. title = "Hello";

19. Hello(); //构造器不能调用可以用super 和this关键字调用

20. }

21. }

and:

30. Hello c = new Hello(5);

31. System.out.print(c.title);

What is the result?

A. Hello

B. Hello World

C. Compilation fails.

D. Hello World 5

E. The code runs with no output.

F. An exception is thrown at runtime.

第36題

Given:

public class Doubler{

public static int doubleMe(Holder h){

return h.getAmount() * 2;

}

}

and:

public class Holder {

int amount = 10;

public void doubleAmount(){amount = Doubler.doubleMe(this);}

public in getAmount(){return amount;}

//more code here

}

Place the code framgmets in position to reduce the coupling between Doubler and Holder. public class Doubler{

public static int doubleMe( Place here h){ //int

return Place here * 2; //h

}

}

相关文档
最新文档