PRO192 - 14

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

B

QN=150 (238) What does the following code fragment print out at line 9? (Choose one.) 1. FileOutputStream fos = new FileOutputStream("xx"); 2. for (byte b=10; b<50; b++) 3. fos.write(b); 4. fos.close(); 5. RandomAccessFile raf = new RandomAccessFile("xx", "r"); 6. raf.seek(10); 7. int i = raf.read(); 8. raf.close() 9. System.out.println("i = " + i); a. The output is i = 30. b. The output is i = 20. c. The output is i = 10. d. There is no output because the code throws an exception at line 1. e. There is no output because the code throws an exception at line 5.

D

QN=151 (126) What does the following code print? public class A { static int x; public static void main(String[] args) { A that1 = new A(); A that2 = new A(); that1.x = 5; that2.x = 1000; x = -1; System.out.println(x); } } a. 0 b. 5 c. 1000 d. -1

B

QN=152 (251) What happens when you try to compile and run the following application? (Choose one.) 1. import java.io.*; 2. 3. public class Xxx { 4. public static void main(String[] args) { 5. try { 6. File f = new File("xxx.ser"); 7. FileOutputStream fos = new FileOutputStream(f); 8. ObjectOutputStream oos = new ObjectOutputStream(fos); 9. oos.writeObject(new Object()); 10. oos.close(); 11. fos.close(); 12. } 13. catch (Exception x) { } 14. } 15. } a. Compiler error at line 9. b. An exception is thrown at line 9. c. An exception is thrown at line 10. d. No compiler error and no exception.

C

QN=153 (59) What happens when you try to compile and run the following code? public class Q { static String s; public static void main(String[] args) { System.out.println(">>" + s + "<<"); } } a. The code does not compile b. The code compiles, and prints out >><< c. The code compiles, and prints out >>null<<

C

QN=154 (230) What happens when you try to compile and run this application? (Choose one.) 1. import java.util.*; 2. 3. public class Apple { 4. public static void main(String[] a) { 5. Set<Apple> set = new TreeSet<Apple>(); 6. set.add(new Apple()); 7. set.add(new Apple()); 8. set.add(new Apple()); 9. } 10. } a. Compiler error. b. An exception is thrown at line 6. c. An exception is thrown at line 7. d. An exception is thrown at line 8. e. No exception is thrown.

C

QN=155 (86) What is -50 >> 2 a. A negative number with very large magnitude. b. A positive number with very large magnitude. c. -13 d. -25 e. 13 f. 25

B

QN=156 (72) What is 7 % -4? a. -3 b. 3 c. -4 d. 4

A

QN=157 (71) What is -8 % 5? a. -3 b. 3 c. -2 d. 2

A

QN=158 (146) What is the difference between the rules for method-call conversion and the rules for assignment conversion? (Choose one.) a. There is no difference; the rules are the same. b. Method-call conversion supports narrowing, assignment conversion does not. c. Assignment conversion supports narrowing, method-call conversion does not. d. Method-call conversion supports narrowing if the method declares that it throws ClassCastException.

A

QN=159 (109) What is the minimal modification that will make this code compile correctly? (Choose one.) 1. final class Aaa 2. { 3. int xxx; 4. void yyy() { xxx = 1; } 5. } 6. 7. 8. class Bbb extends Aaa 9. { 10. final Aaa finalref = new Aaa(); 11. 12. final void yyy() 13. { 14. System.out.println("In method yyy()"); 15. finalref.xxx = 12345; 16. } 17. } a. On line 1, remove the final modifier. b. On line 10, remove the final modifier. c. Remove line 15. d. On lines 1 and 10, remove the final modifier. e. The code will compile as is. No modification is needed.

D

QN=160 (54) What is the range of values that can be assigned to a variable of type byte? (Choose one.) a. Depends on the underlying hardware b. 0 through 2^8 − 1 c. 0 through 2^16 − 1 d. −2^7 through 2^7 − 1 e. −2^15 through 2^15 − 1

D

QN=161 (53) What is the range of values that can be assigned to a variable of type short? (Choose one.) a. Depends on the underlying hardware b. 0 through 2^16 − 1 c. 0 through 2^32 − 1 d. −2^15 through 2^15 − 1 e. −2^31 through 2^31 − 1

A

QN=162 (242) What is the result of attempting to compile and execute the following code fragment? Assume that the code fragment is part of an application that has write permission in the current working directory. Also assume that before execution, the current working directory does not contain a file called datafile. (Choose one.) 1. try { 2. RandomAccessFile raf = new 3. RandomAccessFile("datafile" ,"rw"); 4. BufferedOutputStream bos = new BufferedOutputStream(raf); 5. 6. DataOutputStream dos = new DataOutputStream(bos); 7. 8. dos.writeDouble(Math.PI); 9. dos.close(); 10. bos.close(); 11. raf.close(); 12. } 13. catch (IOException e) { } a. The code fails to compile. b. The code compiles but throws an exception at line 4. c. The code compiles and executes but has no effect on the local file system. d. The code compiles and executes; afterward, the current working directory contains a file called datafile.

D

QN=163 (83) What is the return type of the instanceof operator? a. A reference b. A class c. An int d. A boolean

E

QN=164 (249) What method of the java.io.File class can create a file on the hard drive? (Choose one.) a. newFile() b. makeFile() c. makeNewFile() d. createFile() e. createNewFile()

C

QN=165 (74) What results from attempting to compile and run the following code? 1. public class Conditional { 2. public static void main(String args[]) { 3. int x = 4; 4. System.out.println("value is " + ((x > 4) ? 99.99 : 9)); 5. } 6. } a. The output: value is 99.99 b. The output: value is 9 c. The output: value is 9.0 d. A compiler error at line 4

B

QN=166 (73) What results from running the following code? 1. public class Xor { 2. public static void main(String args[]) { 3. byte b = 10; // 00001010 binary 4. byte c = 15; // 00001111 binary 5. b = (byte)(b ^ c); 6. System.out.println("b contains " + b); 7. } 8. } a. The output: b contains 10 b. The output: b contains 5 c. The output: b contains 250 d. The output: b contains 245

D

QN=167 (150) What would be the output from this code fragment? 1. int x = 0, y = 4, z = 5; 2. if (x > 2) { 3. if (y < 5) { 4. System.out.println("message one"); 5. } 6. else { 7. System.out.println("message two"); 8. } 9. } 10. else if (z > 5) { 11. System.out.println("message three"); 12. } 13. else { 14. System.out.println("message four"); 15. } a. message one b. message two c. message three d. message four

C

QN=168 (78) When a byte is added to a char, what is the type of the result? a. byte b. char c. int d. short e. You can't add a byte to a char.

C

QN=169 (144) When a negative byte is cast to a long, what are the possible values of the result? (Choose one.) a. Positive b. Zero c. Negative d. All the above

D

QN=170 (143) When a negative long is cast to a byte, what are the possible values of the result? (Choose one.) a. Positive b. Zero c. Negative d. All the above

C

QN=171 (79) When a short is added to a float, what is the type of the result? a. short b. int c. float d. You can't add a short to a float.

E

QN=172 (1531) When comparing java.io.BufferedWriter to java.io.FileWriter, which capability exists as a method in only one of the two? (Choose one.) 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

A

QN=173 (165) When does an exception's stack trace get recorded in the exception object? (Choose one.) a. When the exception is constructed b. When the exception is thrown c. When the exception is caught d. When the exception's printStackTrace() method is called

B

QN=174 (163) When is it appropriate to pass a cause to an exception's constructor? (Choose one.) a. Always b. When the exception is being thrown in response to catching of a different exception type c. When the exception is being thrown from a public method d. When the exception is being thrown from a private method

E

QN=175 (166) When is it appropriate to write code that constructs and throws an error? (Choose one.) a. When a public method's preconditions are violated b. When a public method's postconditions are violated c. When a nonpublic method's preconditions are violated d. When a nonpublic method's postconditions are violated e. Never

B

QN=176 (141) When is x & y an int? (Choose one). a. Always b. Sometimes c. When neither x nor y is a float, a long, or a double d. None of the others

A

QN=177 (308) When the user attempts to close the frame window, event in generated. a. window closing b. window resize c. window move d. window close e. window closed

B

QN=178 (312) When the user selects a menu item, event is generated. a. Select event b. Action event c. Item event d. None of the others

A

QN=179 (5694) When you compile a program written in the Java programming language, the compiler converts the human-readable source file into platform- independent code that a Java Virtual Machine can understand. What is this platform-independent code called? a. bytecode b. binary code c. machine code d. cpu instruction


Kaugnay na mga set ng pag-aaral

Chapter 4 - Behavior Therapy and Integrated Psychopharmacology

View Set

Economics- Chapter 21- Protectionism

View Set