A. closing the stream
B. flushing the stream
C. writing to the stream
D. marking a location in the stream
E. writing a line separator to the stream
您可能感兴趣的试卷
你可能感兴趣的试题
10. class MakeFile {
11. public static void main(String[] args) {
12. try {
13. File directory = new File(”d”);
14. File file = new File(directory,”f”);
15. if(!file.exists()) {
16. file.createNewFile();
17. }
18. } catch (IOException e) {
19. e.printStackTrace
20. }
21. }
22. }
The current directory does NOT contain a directory named “d.” Which three are true?()
A. Line 16 is never executed.
B. An exception is thrown at runtime.
C. Line 13 creates a File object named “d”.
D. Line 14 creates a File object named “f‟.
E. Line 13 creates a directory named “d” in the file system.
F. Line 16 creates a directory named “d” and a file “f” within it in the file system.
G. Line 14 creates a file named "f " inside of the directory named “d” in the file system.
public class Wow {
public static void go(short n) {System.out.println(”short”); }
public static void go(Short n) {System.out.println(”SHORT”);}
public static void go(Long n) {System.out.println(” LONG”); }
public static void main(String [] args) {
Short y= 6;
int z=7;
go(y);
go(z);
}
}
What is the result?()
A. short LONG
B. SHORT LONG
C. Compilation fails.
D. An exception is thrown at runtime.
public class Yikes {
public static void go(Long n) {System.out.println(”Long “);}
public static void go(Short n) {System.out.println(”Short “);}
public static void go(int n) {System.out.println(”int “);}
public static void main(String [] args) {
short y= 6;
long z= 7;
go(y);
go(z);
}
}
What is the result?()
A. int Long
B. Short Long
C. Compilation fails.
D. An exception is thrown at runtime.
public class TestString3 {
public static void main(String[] args) {
// insert code here
System.out.println(s);
}
}
Which two code fragments, inserted independently at line 3, generate the output 4247?()
A. String s = “123456789”; s = (s-”123”).replace(1,3,”24”) - “89”;
B. StringBuffer s = new StringBuffer(”123456789”); s.delete(0,3).replace( 1,3, “24”).delete(4,6);
C. StringBuffer s = new StringBuffer(”123456789”); s.substring(3,6).delete( 1 ,3).insert(1, “24”);
D. StringBuilder s = new StringBuilder(”123456789”); s.substring(3,6).delete( 1 ,2).insert( 1, “24”);
E. StringBuilder s = new StringBuilder(”123456789”); s.delete(0,3).delete( 1 ,3).delete(2,5).insert( 1, “24”);
public String makinStrings() {
String s = “Fred”;
s = s + “47”;
s = s.substring(2, 5);
s = s.toUpperCase();
return s.toString();
}
How many String objects will be created when this method is invoked?()
A. 1
B. 2
C. 3
D. 4
E. 5
F. 6
public class MyLogger {
private StringBuilder logger = new StringBuuilder();
public void log(String message, String user) {
logger.append(message);
logger.append(user);
}
}
The programmer must guarantee that a single MyLogger object works properly for a multi-threaded system. How must this code be changed to be thread-safe?()
A. synchronize the log method
B. replace StringBuilder with StringBuffer
C. No change is necessary, the current MyLogger code is already thread-safe.
D. replace StringBuilder with just a String object and use the string concatenation (+=) within the log method
Given this method in a class:
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append(‟<‟);
buffer.append(this.name);
buffer.append(‟>‟);
return buffer.toString();
}
Which is true?()
A. This code is NOT thread-safe.
B. The programmer can replace StringBuffer with StringBuilder with no other changes.
C. This code will perform well and converting the code to use StringBuilder will not enhance the performance.
D. This code will perform poorly. For better performance, the code should be rewritten: return “<“+ this.name + “>”;
11. class Converter {
12. public static void main(String[] args) {
13. Integer i = args[0];
14. int j = 12;
15. System.out.println(”It is “ + (j==i) + “that j==i.”);
16. }
17. }
What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?()
A. It is true that j==i.
B. It is false that j==i.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 13.
public class TestString 1 {
public static void main(String[] args) {
String str = “420”;
str += 42;
System.out.print(str);
}
}
What is the output?()
A. 42
B. 420
C. 462
D. 42042
E. Compilation fails.
F. An exception is thrown at runtime.
1. public class Boxer1 {
2. Integer i;
3. int x;
4. public Boxer1(int y) {
5. x=i+y;
6. System.out.println(x);
7. }
8. public static void main(String[] args) {
9. new Boxer1(new Integer(4));
10. }
11. }
What is the result?()
A. The value “4” is printed at the command line.
B. Compilation fails because of an error in line 5.
C. Compilation fails because of an error in line 9.
D. A NullPointerException occurs at runtime.
E. A NumberFormatException occurs at runtime.
F. An IllegalStateException occurs at runtime.
最新试题
What can be a result?()
What is the result?()
What is the result?()
Which statement is true?()
Which code, inserted at line 4, guarantees that this program will output [1, 2]?()
Which statement is true about the set variable on line 12?()
Given: foo and bar are public references available to many other threads, foo refers to a Thread and bar is an Object. The thread foo is currently executing bar.wait(). From another thread, what provides the most reliable way to ensure that foo will stop executing wait()?()
Which two statements are true?()
What is the result?()
What is the result?()