参数与引用相关:
(1) 这道题相当有价值!必须对堆栈的概念熟悉!
static void test(String str, List<String> lst){
str.replace("1", "2");
lst.add("b");
lst = new ArrayList<String>();
lst.add("c");
}
public static void main(String[] args) {
String str = "1";
List<String> lst = new ArrayList<String>();
lst.add("a");
test(str, lst);
for(String s : lst) System.out.print(s);
System.out.println(str);
}
类加载相关:
(1)
public class InitTest {
/**
* @param args
*/
{
System.out.println("a");
}
static{
System.out.println("b");
}
public InitTest(){
System.out.println("c");
}
public static void main(String[] args) {
System.out.println("d");
new InitTest();
new InitTest();
System.out.println("e");
}
}
Exception相关:
(1)
static int test(){
try{
System.out.println("1");
throw new RuntimeException();
} catch(RuntimeException e){
System.out.println("3");
return 4;
}catch(Exception e){
System.out.println("5");
return 6;
}finally{
System.out.println("7");
return 8;
}
}
public static void main(String[] args) {
System.out.println(test()); // 这里输出的内容?
}
public void doSomething(){
throw new RuntimeException(); // 是否合法?
}
流程题相关:
(1)
int a = 1;
int b = 10;
do{
b -= a;
a++;
}while(b-- < 0);
System.out.println(b);