JAVA - Assessment Test

Ace your homework & exams now with Quizwiz!

A B D

1. Which of the following are valid declarations? Assume java.util.* is imported. A. Vector<Map> v; B. Set<String> s; C. Map<String> m; D. Map<String, String> m;

A B C D E

2. Choose the valid identifiers from those listed here. (Choose all that apply.) A. BigOlLongStringWithMeaninglessName B. $int C. bytes D. $1 E. finalist

D

26. What will be the output of the following code? public class StringTest { public static void main(String [] a) { String s1 = "test string"; String s2 = "test string"; if (s1 == s2) { System.out.println("same"); } else { System.out.println("different"); } } } A. The code will compile but not run. B. The code will not compile. C. "different" will be printed out to the console. D. "same" will be printed out to the console. E. None of the above.

B

27. Java arrays always start at index 1. A. True B. False

D

3. What keyword is used to prevent an object from being serialized? A. private B. volatile C. protected D. transient E. None of the above

D

7. Which of the following statements are true? (Select all that apply.) A. A final object's data cannot be changed. B. A final class can be subclassed. C. A final method cannot be overloaded. D. A final object cannot be reassigned a new address in memory. E. None of the above.

A

8. How can you force garbage collection of an object? A. Garbage collection cannot be forced. B. Call System.gc(). C. Call System.gc(), passing in a reference to the object to be garbage-collected. D. Call Runtime.gc(). E. Set all references to the object to new values (null, for example).

B

1. A signed data type has an equal number of non-zero positive and negative values available. A. True B. False

C

10. Given the following code, what will be the outcome? public class Funcs extends java.lang.Math { public int add(int x, int y) { return x + y; } public int sub(int x, int y) { return x - y; } public static void main(String [] a) { Funcs f = new Funcs(); System.out.println("" + f.add(1, 2)); } } A. The code compiles but does not output anything. B. "3" is printed out to the console. C. The code does not compile. D. None of the above.

D

10. What is the range of values that can be assigned to a variable of type byte? A. Depends on the underlying hardware B. 0 through 28 − 1 C. 0 through 216 − 1 D. −27 through 27 − 1 E. −215 through 215 − 1

C

18. Which of the following are legal? A. char c = 0x1234; B. char c = \u1234; C. char c = '\u1234';

D

29. How do you change the value that is encapsulated by a wrapper class after you have instan- tiated it? A. Use the setXXX() method defined for the wrapper class. B. Use the parseXXX() method defined for the wrapper class. C. Use the equals() method defined for the wrapper class. D. None of the above.

D

11. Given the following code, what is the expected outcome? public class Test { public static void main(String [] a) { int [] b = [1,2,3,4,5,6,7,8,9,0]; System.out.println("a[2]=" + a[2]); } } A. The code compiles but does not output anything. B. "a[2]=3" is printed out to the console. C. "a[2]=2" is printed out to the console. D. The code does not compile. E. None of the above.

B

11. Suppose a source file contains a large number of import statements. How do the imports affect the time required to compile the source file? A. Compilation takes no additional time. B. Compilation takes slightly more time. C. Compilation takes significantly more time.

A

12. Suppose a source file contains a large number of import statements and one class definition. How do the imports affect the time required to load the class? A. Class loading takes no additional time. B. Class loading takes slightly more time. C. Class loading takes significantly more time.

D

12. What is the value of x after the following operation is performed? x = 23 % 4; A. 23 B. 4 C. 5.3 D. 3 E. 5

C.

13. Given the following code, what keyword must be used at line 4 in order to stop execution of the for loop? 1. boolean b = true; 2. for (;;) { 3. if (b) { 4. <insert code> 5. } 6. // do something 7. } A. stop B. continue C. break D. None of the above

A C

13. Which of the following are legal import statements? A. import java.util.Vector; B. static import java.util.Vector.*; C. import static java.util.Vector.*; D. import java.util.Vector static;

B

14. What method call is used to tell a thread that it has the opportunity to run? A. wait() B. notify() C. start() D. run()

B C

14. Which of the following may be statically imported? (Choose all that apply.) A. Package names B. Static method names C. Static field names D. Method-local variable names

A

15. Given the following code, which of the results that follow would you expect? 1. package mail; 2. 3. interface Box { 4. protected void open(); 5. void close(); 6. public void empty(); 7. } A. The code will not compile because of line 4. B. The code will not compile because of line 5. C. The code will not compile because of line 6. D. The code will compile.

C

15. What happens when you try to compile and run the following code? public class Q15 { 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

16. Assertions are used to enforce all but which of the following? A. Preconditions B. Postconditions C. Exceptions D. Class invariants

C D

16. Which of the following are legal? (Choose all that apply.) A. int a = abcd; B. int b = ABCD; C. int c = 0xabcd; D. int d = 0XABCD; E. int e = 0abcd; F. int f = 0ABCD;

B

17. The developer can force garbage collection by calling System.gc(). A. True B. False

D

17. The developer can force garbage collection by calling System.gc(). A. True B. False

A B

17. Which of the following are legal? (Choose all that apply.) A. double d = 1.2d; B. double d = 1.2D; C. double d = 1.2d5; D. double d = 1.2D5;

A C D

18. Select the valid primitive data types. (Select all that apply.) A. boolean B. bit C. char D. float E. All of the above

C

19. Consider the following code: 1. StringBuffer sbuf = new StringBuffer(); 2. sbuf = null; 3. System.gc(); Choose all true statements: A. After line 2 executes, the StringBuffer object is garbage collected. B. After line 3 executes, the StringBuffer object is garbage collected. C. After line 2 executes, the StringBuffer object is eligible for garbage collection. D. After line 3 executes, the StringBuffer object is eligible for garbage

D

19. How many bits does a float contain? A. 1 B. 8 C. 16 D. 32 E. 64

A

2. You can determine all the keys in a Map in which of the following ways? A. By getting a Set object from the Map and iterating through it. B. By iterating through the Iterator of the Map. C. By enumerating through the Enumeration of the Map. D. By getting a List from the Map and enumerating through the List. E. You cannot determine the keys in a Map.

A

20. What is the value of x after the following line is executed? x = 32 x (31 - 10 x 3); A. 32 B. 31 C. 3 D. 704 E. None of the above

B D

20. Which of the following are true? (Choose all that apply.) A. Primitives are passed by reference. B. Primitives are passed by value. C. References are passed by reference. D. References are passed by value.

A

21. A StringBuffer is slower than a StringBuilder, but a StringBuffer is threadsafe. A. True B. False

D

22. Select the list of primitives ordered in smallest to largest bit size representation. A. boolean, char, byte, double B. byte, int, float, char C. char, short, long, float D. char, int, float, long E. None of the above

D

23. Which class provides locale-sensitive text formatting for date and time information? A. java.util.TimeFormat B. java.util.DateFormat C. java.text.TimeFormat D. java.text.DateFormat

B

24. The following line of code is valid. int x = 9; byte b = x; A. True B.Flase

A B C

25. Which of the following code snippets compile? A. Integer i = 7; B. Integer i = new Integer(5); int j = i; C. byte b = 7; D. int i = 7; byte b = i; E. None of the above

C

28. Which of the following statements accurately describes how variables are passed to methods? A. Arguments are always passed by value. B. Arguments are always passed by reference. C. Arguments that are primitive type are passed by value. D. Arguments that are passed with the & operator are passed by reference.

B D

3. Which of the following signatures are valid for the main() method entry point of an application? (Choose all that apply.) A. public static void main() B. public static void main(String arg[]) C. public void main(String [] arg) D. public static void main(String[] args) E. public static int main(String [] arg)

A

30. Suppose you are writing a class that provides custom deserialization. The class implements java.io.Serializable (and not java.io.Externalizable). What method should imple- ment the custom deserialization, and what is its access mode? A. private readObject B. public readObject() C. private readExternal() D. public readExternal()

A

4. An abstract class can contain methods with declared bodies. A. True B. False

D

4. If all three top-level elements occur in a source file, they must appear in which order? A. Imports, package declarations, classes/interfaces/enums B. Classes/interfaces/enums, imports, package declarations C. Package declaration must come first; order for imports and class/interfaces/enum definitions is not significant D. Package declaration, imports, class/interface/enum definitions. E. Imports must come first; order for package declarations and class/interface/enum definitions is not significant

A E

5. Consider the following line of code: int[] x = new int[25]; After execution, which statements are true? (Choose all that apply.) A. x[24] is 0 B. x[24] is undefined C. x[25] is 0 D. x[0] is null E. x.length is 25

E

5. Select the order of access modifiers from least restrictive to most restrictive. A. public, private, protected, default B. default, protected, private, public C. public, default, protected, private D. default, public, protected, private E. public, protected, default, private

D

6. Consider the following application: 1. class Q6 { 2. public static void main(String args[]) { 3. Holder h = new Holder(); 4. h.held = 100; 5. h.bump(h); 6. System.out.println(h.held); 7. } 8. } 9. 10. class Holder { 11. public int held; 12. public void bump(Holder theHolder) { 13. theHolder.held++; } 14. } 15. } What value is printed out at line 6? A. 0 B. 1 C. 100 D. 101

C

6. Which access modifier allows you to access method calls in libraries not created in Java? A. public B. static C. native D. transient E. volatile

C

7. Consider the following application: 1. class Q7 { 2. public static void main(String args[]) { 3. double d = 12.3; 4. Decrementer dec = new Decrementer(); 5. dec.decrement(d); 6. System.out.println(d); 7. } 8. } 9. 10. class Decrementer { 11. public void decrement(double decMe) { 12. decMe = decMe - 1.0; 13. } 14. } What value is printed out at line 6? A. 0.0 B. 1.0 C. 12.3 D. 11.3

A

8. The keyword extends refers to what type of relationship? A. "is a" B. "has a" C. "was a" D. "will be a" E. None of the above

D

9. What is the range of values that can be assigned to a variable of type short? A. Depends on the underlying hardware B. 0 through 216 − 1 C. 0 through 232 − 1 D. −215 through 215 − 1 E. −231 through 231 − 1

B

9. Which of the following keywords is used to invoke a method in the parent class? A. this B. super C. final D. static


Related study sets

examen 2: la seconde guerre mondiale

View Set

MACROECONOMICS: INCOME AND EMPLOYMENT DETERMINATION (set 2)

View Set

CA Real Estate Principles | Chapter 5 Quiz

View Set

Chapter 13. The Nekton: Swimmers of the Sea

View Set

故事一 (对话) Story 1 (Conversation) - Jess and Curly Had a Farm

View Set