public class Pass{ public static void main(String[]args){ int x=5; Pass p=new Pass(); p.doStuff(x); System.out.print("mainx="+x); } void doStuff(intx){ System.out.print("doStuffx="+x++); } } What is the result?()
第1题:
static void test() throws RuntimeException { try { System.out.print(”test “); throw new RuntimeException(); } catch (Exception ex) { System.out.print(”exception “); } } public static void main(String[] args) { try { test(); } catch (RuntimeException ex) { System.out.print(”runtime “); } System.out.print(”end “); } What is the result?()
第2题:
interface DeclareStuff{ public static final int EASY = 3; void doStuff(int t); } public class TestDeclare implements DeclareStuff { public static void main(String [] args) { int x=5; new TestDeclare().doStuff(++x); } void doStuff(int s) { s += EASY + ++s; System.out.println(”s “ + s); } } What is the result?()
第3题:
public class X { public static void main(String [] args) { try { badMethod(); System.out.print(“A”); } catch (Exception ex) { System.out.print(“C”); } finally { System.out.print(“B”); } System.out.print(“D”); } public static void badMethod() { throw new Error(); } } What is the result?()
第4题:
Given the command line java Pass2 and: public class Pass2 { public void main(String [] args) { int x=6; Pass2 p = new Pass2(); p.doStuff(x); System.out.print(” main x = “+ x); } void doStuff(int x) { System.out.print(” doStuffx = “+ x++); } } What is the result?()
第5题:
public class Pass { public static void main(String [1 args) { int x 5; Pass p = new Pass(); p.doStuff(x); System.out.print(” main x = “+ x); } void doStuff(int x) { System.out.print(” doStuff x = “+ x++); } } What is the result?()
第6题:
public class X { public static void main(String [] args) { try { badMethod(); System.out.print(“A”); } catch (Exception ex) { System.out.print(“B”); } finally { System.out.print(“C”); } System.out.print(“D”); } public static void badMethod() { throw new RuntimeException(); } } What is the result? ()
第7题:
BD
BCD
BDE
BCDE
ABCDE
Compilation fails.
第8题:
Compilation fails.
An exception is thrown at runtime.
doStuffx = 6 main x = 6
doStuffx = 5 main x = 5
doStuffx = 5 main x = 6
doStuffx = 6 main x = 5
第9题:
ABCD
Compilation fails.
C is printed before exiting with an error message.
BC is printed before exiting with an error message.
BCD is printed before exiting with an error message.
第10题:
Compilation fails.
An exception is thrown at runtime.
The code executes normally and prints “bar”.
The code executes normally, but nothing prints.
第11题:
AC
BD
ACD
ABCD
Compilation fails.
第12题:
Compilation fails.
An exception is thrown at runtime.
doStuff x=6 main x=6
doStuff x=5 main x=5
doStuff x=5 main x=6
doStuff x=6 main x=5
第13题:
public class Threads5 { public static void main (String[] args) { new Thread(new Runnable() { public void run() { System.out.print(”bar”); } }).start(); } } What is the result?()
第14题:
Given the command line java Pass2 and: public class Pass2{ public void main(String[]args){ int x=6; Pass2 p=new Pass2(); p.doStuff(x); System.out.print("mainx="+x); } void doStuff(intx){ System.out.print("doStuffx="+x++); } } What is the result?()
第15题:
static void test() { try { String x=null; System.out.print(x.toString() +“ “); } finally { System.out.print(“finally “); } } public static void main(String[] args) { try { test(); } catch (Exception ex) { System.out.print(”exception “); } } What is the result?()
第16题:
public class X { public static void main(String [] args) { try { badMethod(); System.out.print(“A”); } catch (Exception ex) { System.out.print(“B”); } finally { System.out.print(“C”); } System.out.print(“D”); } public static void badMethod() {} } What is the result?()
第17题:
public class X { public static void main(String [] args) { try { badMethod(); System.out.print(“A”); } catch (RuntimeException ex) { System.out.print(“B”); } catch (Exception ex1) { System.out.print(“C”); } finally { System.out.print(“D”); } System.out.print(“E”); } public static void badMethod() { throw new RuntimeException(); } } What is the result?()
第18题:
static void test() throws Error { if (true) throw new AssertionError(); System.out.print(”test “); } public static void main(String[] args) { try { test(); } catch (Exception ex) { System.out.print(”exception “); } System.out.print(”elld “); } What is the result?()
第19题:
null
finally
null finally
Compilation fails.
finally exception
第20题:
Compilation fails.
An exception is thrown at runtime.
doStuffx = 6 main x = 6
doStuffx = 6 main x = 7
doStuffx = 7 main x = 6
doStuffx = 7 main x = 7
第21题:
Compilation fails.
An exception is thrown at runtime.
doStuffx=6 main x=6
doStuffx=6 mainx =7
doStuffx=7 mainx =6
doStuffx=7 mainx =7
第22题:
AB
BC
ABC
BCD
Compilation fails.
第23题:
s 14
s 16
s 10
Compilation fails.
An exception is thrown at runtime.