Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区 » 学习心得/方法/资源  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 一道公司面试题,大家看一下
liyan811101





发贴: 11
积分: 0
于 2007-08-10 09:53 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public class Test1
{
  public static void a(){
    System.out.println("123");
  }
  public static void main(String [] args){
    Test1 t=null ;
    t.a();
  }
}
抛不抛异常
抛什么异常。
public class Test
{
  public static void a(){
    System.out.println("123");
  }
  public static void main(String [] args){
    Test t;
    t.a();
  }
}
抛不抛异常
抛什么异常。
不许上机运行。



作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
gxy_1227





发贴: 3
积分: 0
于 2007-08-10 11:26 user profilesend a private message to usersend email to gxy_1227search all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
很明显不抛异常


我爱编程,没有理由!
作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
Cappuccino





发贴: 49
积分: 4
于 2007-08-10 14:33 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
static....


作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
liyan811101





发贴: 11
积分: 0
于 2007-08-10 17:13 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
那第二道呢


作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
snowbug



CJSDN高级会员


发贴: 418
积分: 130
于 2007-08-10 23:18 user profilesend a private message to usersend email to snowbugsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
编译错误,本地变量未初始化。


作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
liangx





发贴: 37
积分: 0
于 2007-08-12 18:09 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
这也要问? 写个测试代码自己就知道了.


作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
menzy



版主


发贴: 754
积分: 113
于 2007-08-13 15:51 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
变异都可能过不了

不过公司考这样的问题没啥意思啊



作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
JiafanZhou



版主


发贴: 736
积分: 61
于 2007-08-14 23:25 user profilesend a private message to usersend email to JiafanZhousearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
这个说明面试的人以前认为会有异常。。。


When I was a kid I used to pray every night for a new bike. Then I realized that The Lord doesn't work that way, so I stole one and asked him to forgive me.
作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
luofeifly





发贴: 1
积分: 0
于 2007-09-03 19:53 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
第一个不抛出异常;
第二个的 t 没初始化,应该是个对象应用而已。



作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
hcs_1018





发贴: 23
积分: 0
于 2007-10-26 20:18 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
同意楼上的...让自己理解更深入勒点..对数据初始化


相信明天会更好!! I LOVE YOU ~ JAVA.
GOODS!
作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
useforever





发贴: 11
积分: 0
于 2007-10-28 21:23 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
第一感觉是:第一个不会抛异常,因为null也应该是对象吧.第二个会抛异常,因为没有实例化,不是具体对象.


I can you can.
作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
useforever





发贴: 11
积分: 0
于 2007-10-28 21:27 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
刚去试了一下,错了!其实两个都不会抛异常,第一个编译运行都通过,第二个编译错误.编译错误和抛异常完全是两个概念,呵呵,这道题目还是有点意思.


I can you can.
作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
lvbaolei724





发贴: 1
积分: 0
于 2008-04-11 20:12 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
static方法一般用”类名.静态方法名“引用吧~~~~~


作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
ccxuejava





发贴: 6
积分: 0
于 2008-04-16 11:37 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
第一个不用抛异常
"a()"是个静态方法



作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
ZCJ_88





发贴: 2
积分: 0
于 2008-04-16 18:47 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
第一个不抛异常..因为方法a()是static,对象是null,静态方法可以直接使用,就算是null.a()也可以运行.....


作者 Re:一道公司面试题,大家看一下 [Re:liangx]
hzpfly





发贴: 2
积分: 0
于 2008-08-11 16:47 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
不好意思,我运行了一下.结果是:
第一个可以;
第二个不可以,错误提示为:variable t might not have been initialized。



作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
ditty

负资产小资

CJSDN高级会员


发贴: 1038
积分: 143
于 2008-08-11 21:50 user profilesend a private message to usersend email to dittysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
这个问题确实很没劲,无论抛不抛异常,这种静态成员函数的用法,都是不可取的。


内忧外患的时代,洗心革面,阿咪豆腐~
作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
rbible

Einstein



发贴: 12
积分: 0
于 2008-08-12 00:08 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
楼主
这题目还真是挺有意思。

我想
第一个抛空指针,
第二个抛没有初始化




作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
rbible

Einstein



发贴: 12
积分: 0
于 2008-08-12 00:14 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list


只对了一个




作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
linxiujian





发贴: 1
积分: 0
于 2008-08-13 12:02 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
没什么意义,特别是对开发而言。


作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
小寒1943





发贴: 4
积分: 0
于 2008-10-07 15:02 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
第一个抛NullPointerException
第二个不抛异常。。

个人观点,请雅正。。。。。



作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
raoaming





发贴: 2
积分: 0
于 2008-10-18 21:16 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
空指针可以指向方法吗?



作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
David_Liu





发贴: 5
积分: 0
于 2008-10-19 09:49 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
第一个正确
第二个没初始化,换成Test t=null ;或者直接谢Test.a();



作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
ysl_Java





发贴: 1
积分: 0
于 2008-10-19 22:37 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
都没异常
不过第二道要对t初始化



作者 Re:一道公司面试题,大家看一下 [Re:liyan811101]
zhchuang





发贴: 1
积分: 0
于 2008-11-11 21:53 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
第一个应该不抛异常,也没什么错误,一改可以运行的,空指针可以调用静态方法的。
第二个编译我想都通不过,更不用说抛什么异常了。错误和异常是两码事,如果在面试时候说这个变量没有初始化,应该抛出异常,就贻笑大方了。




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923