1、下面程序的运行结果是 B
String str1 = “hello”;
String str2 = “he” + new String(“llo”);
System.err.println(str1 == str2);
A、true
B、false
C、exception
D、无输出
解析:
String str1 = “hello”;这里的str1指的是方法区的字符串常量池中的“hello”,编译时期就知道的;
String str2 = “he” + new String(“llo”);这里的str2必须在运行时才知道str2是什么,所以它是指向的是堆里定义的字符串“hello”,所以这两个引用是不一样的。
2、以下程序运行的结果为 ( A )
publicclassExample extendsThread{
@Override
publicvoidrun(){
try{
Thread.sleep(1000);
} catch(InterruptedException e){
e.printStackTrace();
}
System. out.print( “run” );
}
publicstaticvoidmain(String[] args){
Example example= newExample();
examp