分享:一道BT试题
2008-03-21 14:38
337 查看
http://topic.csdn.net/u/20070113/21/9287c503-51fb-4979-9935-9d739aaab3ef.html
近日,在下到某公司面试,满怀信心的我重重的载在那份BT试题上。
其中一道:
以下code生成几个String对象
String a= "abc ";
String b= "abc ";
String c=new String( "abc ");
String d=c.intern();
当时在下毫不忧郁的选3。
后来在Java Language Specification/CHAPTER 3/Lexical Structure发现这样一个测试代码,知道错了。
package testPackage;
class Test {
public static void main(String[] args) {
String hello = "Hello ", lo = "lo ";
System.out.print((hello == "Hello ") + " ");
System.out.print((Other.hello == hello) + " ");
System.out.print((other.Other.hello == hello)+ " ");
System.out.print((hello == ( "Hel "+ "lo ")) + " ");
System.out.print((hello == ( "Hel "+lo)) + " ");
System.out.println(hello == ( "Hel "+lo).intern());
}
}
class Other { static String hello = "Hello "; }
学海无崖,顿感羞愧,特此分享。
近日,在下到某公司面试,满怀信心的我重重的载在那份BT试题上。
其中一道:
以下code生成几个String对象
String a= "abc ";
String b= "abc ";
String c=new String( "abc ");
String d=c.intern();
当时在下毫不忧郁的选3。
后来在Java Language Specification/CHAPTER 3/Lexical Structure发现这样一个测试代码,知道错了。
package testPackage;
class Test {
public static void main(String[] args) {
String hello = "Hello ", lo = "lo ";
System.out.print((hello == "Hello ") + " ");
System.out.print((Other.hello == hello) + " ");
System.out.print((other.Other.hello == hello)+ " ");
System.out.print((hello == ( "Hel "+ "lo ")) + " ");
System.out.print((hello == ( "Hel "+lo)) + " ");
System.out.println(hello == ( "Hel "+lo).intern());
}
}
class Other { static String hello = "Hello "; }
学海无崖,顿感羞愧,特此分享。
相关文章推荐
- 一道机试题,拿出来和大家分享一下,稍候贴出我做的代码(C#)
- 分享一道关于闭包、bind和this的面试题
- 一道SQL统计试题
- 分享一套 python 试题
- 一道百度试题
- 2014年七月华为校招机试题目--最难的一道, 呵呵!
- 一道中兴试题的解析
- 一道腾讯校招试题
- 某公司的一道试题
- 分享一道汇编题,然后说下微机原理和汇编语言哪个简单
- 一道金蝶校园招聘试题数据库笔试题
- 一道C++试题的出题考虑和考后反思
- 华为的一道机试题,单词倒序
- 一道受用终身的试题,看完不回者,斩~!超经典~!~!
- 学习<<汇编语言 -王爽>>,自已完成的一道实试题 (4)
- 迅雷的一道机试题___URL解析
- 一道Baidu在线试题:论坛数据库设计
- 一道经典试题的Python实现
- 一道表达式的经典试题
- 一道某高大上互联网公司的笔试题分享