单项选择题

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?()  

A. The program prints “lava”
B. The program prints “java”
C. An error at line 7 causes compilation to fail.
D. Compilation succeeds but the program throws an exception.


您可能感兴趣的试卷

你可能感兴趣的试题

3.单项选择题

public class SyncTest { 
private int x;  
private int y;  
public synchronized void setX (int i) (x=1;)  
public synchronized void setY (int i) (y=1;)  
public synchronized void setXY(int 1)(set X(i); setY(i);)  
public synchronized Boolean check() (return x !=y;)  
}  
Under which conditions will check () return true when called from a different class? 

A. Check() can never return true.
B. Check() can return true when setXY is called by multiple threads.
C. Check() can return true when multiple threads call setX and setY separately.
D. Check() can only return true if SyncTest is changed to allow x and y to be set separately.

4.单项选择题

public class X implements Runnable(  
 private int x;  
private int y; 
 public static void main(Stringargs) 
X that = new X();  
(new Thread(that)).start(); 
(new Thread(that)).start(); 
) 
public void run() ( 
for (;;) ( 
x++;  
y++;  
System.out.printIn(“x=” + x + “, y = ” + y);  
)  
)  
What is the result?()  

A. Errors at lines 7 and 8 cause compilation to fail.
B. The program prints pairs of values for x and y that might not always be the same on the same line  (for example, “x=2, y=1”).
C. The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by  “x=1, y=1”).
D. The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears only for once (for example, “x=1, y=1”  followed by “x=2, y=2”).

5.单项选择题Which statement is true for the class java.util.ArrayList?() 

A. The elements in the collection are ordered.
B. The collection is guaranteed to be immutable.
C. The elements in the collection are guaranteed to be unique.
D. The elements in the collection are accessed using a unique key.
E. The elements in the collections are guaranteed to be synchronized.

6.多项选择题You need to store elements in a collection that guarantees that no duplicates are stored. Which two interfaces provide that capability?()

A. Java.util.Map
B. Java.util.Set
C. Java.util.List
D. Java.util.StoredSet
E. Java.util.StoredMap
F. Java.util.Collection

9.单项选择题

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?()

A. The output is x = 6 y = 0
B. The output is x = 7 y = 0
C. The output is x = 6 y = -1
D. The output is x = 7 y = -1
E. Compilation will fail.

10.单项选择题

public class X {  
public static void main (String args) {  
byte b = 127;  
byte c = 126;  
byte d = b + c;  
}  
}  
Which statement is true?()  

A. Compilation succeeds and d takes the value 253.
B. Line 5 contains an error that prevents compilation.
C. Line 5 throws an exception indicating “Out of range”
D. Line 3 and 4 contain error that prevent compilation.
E. The compilation succeeds and d takes the value of 1.