字符串String
String不可变特性(值传递、引用传递)
public class TestStringFinal {
public static void main(String[] args) {
String a = "hello";
change(a);
System.out.println(a);
}
public static void change(String name) {
name = "world";
}
}
结果为:hello
public class TestString {
public void change(String str, char ch[]) {
str = "test ok";
ch[0] = 'g';
}
public static void main(String args[]) {
String str = new String("good");
char[] ch = { 'a', 'b', 'c' };
TestString ex = new TestString();
ex.change(str, ch);
System.out.print(str + " and ");
System.out.print(ch);
}
}
结果为:good and gbc
3、写出下列程序的运行结果
结果为:
true
false
true
true
true
false
true
多线程
多线程中start()和run()方法
public class TestRunAndStart {
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");
}
}
结果为:pongping