Compilation fails.
An exception is thrown at runtime.
doStuff x = 6 main x = 6
doStuff x = 6 main x = 7
doStuff x = 7 main x = 6
第1题:
public class WhileFoo { public static void main (String []args) { int x= 1, y = 6; while (y--) {x--;} system.out.printIn(“x=” + x “y =” + y); } } What is the result?()
第2题:
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?()
第3题:
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?()
第4题:
public class Test { private static int[] x; public static void main(String[] args) { System.out.println(x[0]); } } What is the result?()
第5题:
public class TestOne { public static void main (String[] args) throws Exception { Thread.sleep(3000); System.out.println(”sleep”); } } What is the result?()
第6题:
Which two code fragments are most likely to cause a StackOverflowError?()
第7题:
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
第8题:
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
第9题:
4
5
8
9
Compilation fails.
An exception is thrown at runtime.
It is impossible to determine for certain.
第10题:
The output is x = 6 y = 0
The output is x = 7 y = 0
The output is x = 6 y = -1
The output is x = 7 y = -1
Compilation will fail.
第11题:
s 14
s 16
s 10
Compilation fails.
An exception is thrown at runtime.
第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题:
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?()
第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(” main x = “+ x); } void doStuff(int x) { System.out.print(” doStuffx = “+ x++); } } What is the result?()
第15题:
1. class SuperFoo { 2. SuperFoo doStuff(int x) { 3. return new SuperFoo(); 4. } 5. } 6. 7. class Foo extends SuperFoo { 8. //insert code here 9. } 下面哪三项分别插入到第8行,可以编译?()
第16题:
public class Starter extends Thread { private int x= 2; public static void main(String[] args) throws Exception { new Starter().makeItSo(); } public Starter() { x=5; start(); } public void makeItSo() throws Exception { join(); x=x- 1; System.out.println(x); } public void run() { x *= 2; } } What is the output if the main() method is rum?()
第17题:
现有: 1.class SuperFoo{ 2.SuperFoo doStuff (int x) { 3.return new SuperFoo(); 4. } 5. } 6. 7. class Foo extends SuperFoo { 8. //insert code here 9. } 和四个声明: Foo doStuff (int x) { return new Foo(); } Foo doStuff (int x) { return new SuperFoo(); } SuperFoo doStuff(int x) { return new Foo(); } SuperFoo doStuff(int y) { return new SuperFoo(); } 分别插入到第8行,有几个可以通过编泽?()
第18题:
0
null
Compilation fails.
A NullPointerException is thrown at runtime.
An ArrayIndexOutOfBoundsException is thrown at runtime.
第19题:
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
第20题:
doStuff x = 6 main x = 6
Compilation fails.
doStuff x = 6 main x = 7
An exception is thrown at runtime.
doStuff x = 7 main x = 6
doStuff x = 7 main x = 7
第21题:
1
2
3
4
第22题:
test end
Compilation fails.
test runtime end
test exception end
A Throwable is thrown by main at runtime.
第23题:
a b
b c
a b c
Compilation fails.
An exception is thrown at runtime.