| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 755 人关注过本帖
标题:帮忙看一下
只看楼主 加入收藏
pine
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2004-8-10
收藏
 问题点数:0 回复次数:3 
帮忙看一下

1. public class Test2 extends MyBase implements MyInterface { int x = 0; 5. public Test2(int inVal) throws Exception { 7. if( inVal != this.x) { 9. throw new Exception("Invalid input"); } } public static void main(String[] args) { 15. Test2 t = new Test2(4); } }

A.the code fails to compile at line1. it's not valid to both implement an interface and extends from a parent class simultaneously.

B.the code fails to compile at line 5.int's not valid for constructors to throw exceptions.

C.the code fails to compile at line9,because this is not valid way to throw an exception.

D.the code fails to compile at line15.the compiler complains that there is an uncaught exception.

E.the code fails to compile at line7,because this is not a valid way to reference variable x.

答案是D,可是我选了A,大家帮帮忙看一下,如果选D帮忙解释一下,谢谢了

搜索更多相关主题的帖子: class void interface public parent 
2004-08-16 13:25
tempnetbar
Rank: 2
等 级:新手上路
威 望:4
帖 子:582
专家分:4
注 册:2004-5-5
收藏
得分:0 

你选A那是大错特错,呵呵,不过这题除了学D其他在我看来都是大错特错,开个玩笑,不过说真的,我一眼看出选D,所以觉得你选A很不可思议。不知道你为什么选A,可以告诉我你的想法吗?这个很重要,这样就能知道你什么知识点没掌握了,因为我觉得没有一本书说这样是不可以的,哈~

D因为构造函数声明抛出异常,那么引用它的函数就要负责捕获异常或是再向上抛出,这里main()函数并没有作任何处理,所以错了


相信勤能补拙! 喜欢用好用的就永远学不到有用的。
2004-08-16 17:31
pine
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2004-8-10
收藏
得分:0 

哦。明白了~~我真是笨啊~呵呵,谢谢了~~非常感谢~~~

2004-08-17 13:22
tempnetbar
Rank: 2
等 级:新手上路
威 望:4
帖 子:582
专家分:4
注 册:2004-5-5
收藏
得分:0 
:-)

相信勤能补拙! 喜欢用好用的就永远学不到有用的。
2004-08-17 14:55
快速回复:帮忙看一下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014968 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved