叨叨兩句
- 心情跌宕起伏,好現象,感性的力量能夠提升自個人彈性,作個太剛性的人並非我所期待的。
- 讓你滿意的事情,未必是現實結果最好的,主觀和客觀要分清。
題37
下面程序的運行結果是
String str1 = "hello";
String str2 = "he" + new String("llo");
System.err.println(str1 == str2);
String str1 = "hello";這裏的str1指的是方法區的字符串常量池中的「hello」,編譯時期就知道的; String str2 = "he" + new String("llo");這裏的str2必須在運行時才知道str2是什麼,因此它是指向的是堆裏定義的字符串「hello」,因此這兩個引用是不同的。
若是用str1.equal(str2),那麼返回的是True;由於兩個字符串的內容同樣。
題38
下列說法正確的有( )
A. class中的constructor不可省略
B. constructor必須與class同名,但方法不能與class同名
C. constructor在一個對象被new時執行
D. 一個class只能定義一個constructor
選C
重點說B,方法名能夠與類名一致,方法與構造方法的惟一區別是有無返回值。
題39
下面程序的運行結果:()
public static void main(String args[]) {
Thread t = new Thread() {
public void run() {
pong();
}
};
t.run();
System.out.print("ping");
}
static void pong() {
System.out.print("pong");
}
A pingpong B pongping C pingpong和pongping都有可能 D 都不輸出
如果t.run(),則只是普通的方法調用,選B
如果t.start(),則是開啓一個線程,因爲存在搶奪執行權的問題,選C