public class Yippee2 { static public void main(String [] yahoo) { for(int x= 1; x
第1题:
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?()
第2题:
public class X { public static void main (Stringargs) { int a = new int [1] modify(a); System.out.printIn(a[0]); } public static void modify (int a) { a[0] ++; } } What is the result?()
第3题:
package foo; import java.util.Vector; private class MyVector extends Vector { int i = 1; public MyVector() { i = 2; } } public class MyNewVector extends MyVector { public MyNewVector() { i = 4; } public static void main(String args[]) { MyVector v = new MyNewVector(); } } What is the result?()
第4题:
public class IfTest ( public static void main(string[]args) { int x = 3; int y = 1; if (x = y) system.out.printIn(“Not equal”); else system.out.printIn(“Equal”); } ) What is the result?()
第5题:
public class test( public static void main(stringargs){ string foo = args [1]; string foo = args ; string foo = args ; } ) And command line invocation: Java Test red green blue What is the result? ()
第6题:
package foo; import java.util.Vector; private class MyVector extends Vector { int i = 1; public MyVector() { i = 2; } } public class MyNewVector extends MyVector { public MyNewVector () { i = 4; } public static void main (String args ) { MyVector v = new MyNewVector(); } } The file MyNewVector.java is shown in the exhibit. What is the result?()
第7题:
0
null
Compilation fails.
A NullPointerException is thrown at runtime.
An ArrayIndexOutOfBoundsException is thrown at runtime.
第8题:
baz =
baz = null
baz = blue
Compilation fails.
An exception is thrown at runtime.
第9题:
x = 0
x = 42
Compilation fails because of an error in line 2 of class Test2.
Compilation fails because of an error in line 3 of class Test1.
Compilation fails because of an error in line 4 of class Test2.
第10题:
s 14
s 16
s 10
Compilation fails.
An exception is thrown at runtime.
第11题:
ab
bc
abc
Compilation fails.
An exception is thrown at runtime.
第12题:
The program runs and prints “0”
The program runs and prints “1”
The program runs but aborts with an exception.
An error “possible undefined variable” at line 4 causes compilation to fail.
An error “possible undefined variable” at line 9 causes compilation to fail.
第13题:
public class Yippee2{ stati cpublic void main(String[]yahoo){ for(intx=1;x
第14题:
public class Test { public static void main( String[] args) { String foo = args[1]; String bar = args[2]; String baz = args[3]; System.out.println(“baz = “ + baz); } } And the command line invocation: java Test red green blue What is the result?()
第15题:
public class Test { public static void replaceJ(string text) { text.replace (‘j’, ‘l’); } public static void main(String args[]) { string text = new String (“java”) replaceJ(text); system.out.printIn(text); } } 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题:
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?()
第18题:
class A { public int getNumber(int a) { return a + 1; } } class B extends A { public int getNumber (int a) { return a + 2 } public static void main (String args) { A a = new B(); System.out.printIn(a.getNumber(0)); } } What is the result? ()
第19题:
The output is “Equal”
The output in “Not Equal”
An error at line 5 causes compilation to fall.
The program executes but does not print a message.
第20题:
Compilation succeeds.
Compilation fails because of an error at line 5.
Compilation fails because of an error at line 6.
Compilation fails because of an error at line 14.
Compilation fails because of an error at line 17.
第21题:
Hello
Hello Foo
Hello world
Compilation fails.
The code does not run.
第22题:
a b
b c
a b c
Compilation fails.
An exception is thrown at runtime.
第23题:
Compilation will succeed.
Compilation will fail at line 5.
Compilation will fail at line 6.
Compilation will fail at line 14.
Compilation will fail at line 17.