chensifeng 2012-07-09 14:20
浏览 180
已采纳

请教两个JAVA问题

第一题:(答案:F)

Given the following method signatures from ArrayList:
boolean add(E e)
protected void removeRange(int fromIndexInclusive, int toIndexExclusive)
int size()
and given:

 

 

2. import java.util.*;
3. public class MyUtil extends ArrayList {
4. public static void main(String[] args) {
5. MyUtil m = new MyUtil();
6. m.add("w"); m.add("x"); m.add("y"); m.add("z");
7. m.removeRange(1,3);
8. System.out.print(m.size() + " ");
9. MyUtil m2 = new MyUtil2().go();
10. System.out.println(m2.size());
11. }
12. }
13. class MyUtil2 {
14. MyUtil go() {
15. MyUtil m2 = new MyUtil();
16. m2.add("1"); m2.add("2"); m2.add("3");
17. m2.removeRange(1,2);
18. return m2;
19. } }

 

What is the result?

A. 1 1

B. 1 2

C. 2 1

D. 2 2

E. An exception is thrown at runtime.

F. Compilation fails due to a single error.

G. Compilation fails due to multiple errors.

 

第二题:(答案:F)

Given:

 

1. public class Hose <E extends Hose> {
2. E innerE;
3. public static E doStuff(E e, Hose<E> e2) {
4. // insert code here
5. }
6. public E getE() {
7. return innerE;
8. } }

 Which can be inserted, independently at line 4, for the code to compile? (Choose all that apply.)

A. return e;

B. return e.getE();

C. return e2;

D. return e2.getE();

E. return new Hose().getE();

F. Compilation fails regardless of which return is inserted.

 

 

请大家帮忙解释下原因,多谢啦!

  • 写回答

3条回答 默认 最新

  • iteye_12540 2012-07-09 15:03
    关注

    removeRange是protected方法,在ArrayList及其子类以外是不可见的。

    E是动态类型的范型,静态是不能用的。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。