public class X {
public static void main (String[]args) {
string s = new string (“Hello”);
modify(s);
System.out.printIn(s);
}
public static void modify (String s) {
s += “world!”;
}
}
What is the result?()
A. The program runs and prints “Hello”
B. An error causes compilation to fail.
C. The program runs and prints “Hello world!”
D. The program runs but aborts with an exception.
您可能感兴趣的试卷
你可能感兴趣的试题
public class Foo {
public static void main (String []args) {
int i = 1;
int j = i++;
if ((i>++j) && (i++ ==j)) {
i +=j;
}
}
}
What is the final value of i?()
A. 1
B. 2
C. 3
D. 4
E. 5
public class X {
public static void main (String[]args) {
String s1 = new String (“true”);
Boolean b1 = new Boolean (true);
if (s2.equals(b1)) {
System.out.printIn(“Equal”);
}
}
}
What is the result?()
A. The program runs and prints nothing.
B. The program runs and prints “Equal”
C. An error at line 5 causes compilation to fail.
D. The program runs but aborts with an exception.
String foo = “blue”;
Boolean[]bar = new Boolean [1];
if (bar[0]) {
foo = “green”;
}
What is the result? ()
A. Foo has the value of “”
B. Foo has the value of null.
C. Foo has the value of “blue”
D. Foo has the value of “green”
E. An exception is thrown.
F. The code will not compile.
A. Char ch = “a”;
B. Char ch = ‘\’ ‘;
C. Char ch = ‘cafe’;
D. Char ch = “cafe”;
E. Char ch = ‘\ucafe’;
F. Char ch = ‘\u10100’;
G. Char ch = (char) true;
public class foo {
static String s;
public static void main (String[]args) {
system.out.printIn (“s=” + s);
}
}
What is the result?()
A. The code compiles and “s=” is printed.
B. The code compiles and “s=null” is printed.
C. The code does not compile because string s is not initialized.
D. The code does not compile because string s cannot be referenced.
E. The code compiles, but a NullPointerException is thrown when toString is called.
public interface Foo{
int k = 4;
}
Which three are equivalent to line 2?()
A. Final int k = 4;
B. Public int k = 4;
C. Static int k = 4;
D. Private int k = 4;
E. Abstract int k = 4;
F. Volatile int k = 4;
int index = 1;
String [] test = new String[3];
String foo = test[index];
What is the result?()
A. Foo has the value “”
B. Foo has the value null
C. An exception is thrown
D. The code will not compile
public class Test {
public static void main (String[]args) {
String foo = args[1];
String bar = args[2];
String baz = args[3];
System.out.printIn(“baz = ” + baz);
}
}
And the output:
Baz = 2
Which command line invocation will produce the output?()
A. Java Test 2222
B. Java Test 1 2 3 4
C. Java Test 4 2 4 2
D. Java Test 4 3 2 1
1. package foo;
2.
3. import java.util.Vector;
4.
5. private class MyVector extends Vector {
6. int i = 1;
7. public MyVector() {
8. i = 2;
9. }
10. }
11.
12. public class MyNewVector extends MyVector {
13. public MyNewVector () {
14. i = 4;
15. }
16. public static void main (String args []) {
17. MyVector v = new MyNewVector();
18. }
19. }
The file MyNewVector.java is shown in the exhibit. What is the result?()
A. Compilation will succeed.
B. Compilation will fail at line 5.
C. Compilation will fail at line 6.
D. Compilation will fail at line 14.
E. Compilation will fail at line 17.
class super {
public int getLength() {return 4;}
}
public class Sub extends Super {
public long getLength() {return 5;}
public static void main (String[]args) {
super sooper = new Super ();
Sub sub = new Sub();
System.out.printIn(
sooper.getLength()+ “,” + sub.getLength() };
}
What is the output?()
A. 4, 4
B. 4, 5
C. 5, 4
D. 5, 5
E. The code will not compile.
最新试题
Given that Triangle implements Runnable, and:Which two statements, inserted independently at both lines 35 and 41, tend to allow both threads to temporarily pause and allow the other thread to execute?()
What is the result?()
Which statement is true?()
A programmer iterates over the TreeSet and prints the name of each Drink object. What is the result?()
Which two of statements are true?()
What is the result?()
Which statement is true?()
Which two statements are true?()
What is the result?()
What is the result?()