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
第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题:
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行,可以编译?()
第5题:
public class Test { public static void main(String[] args) { int x = 0; assert (x > 0): “assertion failed”; System.out.println(“finished”); } } What is the result?()
第6题:
Which two code fragments are most likely to cause a StackOverflowError?()
第7题:
0
null
Compilation fails.
A NullPointerException is thrown at runtime.
An ArrayIndexOutOfBoundsException is thrown at runtime.
第8题:
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
第9题:
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
第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题:
a b
b c
a b c
Compilation fails.
An exception is thrown at runtime.
第12题:
finished
Compilation fails.
An AssertionError is thrown.
An AssertionError is thrown and finished is output.
第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题:
public class Yippee { public static void main(String [] args) { for(int x = 1; x < args.length; x++) { System.out.print(args[x] +“ “); } } } and two separate command line invocations: java Yippee java Yippee 1234 What is the result?()
第16题:
public class Test { private static int[] x; public static void main(String[] args) { System.out.println(x[0]); } } What is the result?()
第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题:
No output is produced. 123
No output is produced. 234
No output is produced. 1234
An exception is thrown at runtime. 123
An exception is thrown at runtime. 234
An exception is thrown at rijntime. 1234
第19题:
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
第20题:
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
第21题:
1
2
3
4
第22题:
s 14
s 16
s 10
Compilation fails.
An exception is thrown at runtime.
第23题:
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