pro192 om

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which modifier or modifiers should be used to denote a variable that should not be written out as part of its class's persistent state? (Choose the shortest possible answer.) A. private B. protected C. private protected D. transient E. volatile

D. transient

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

a. Integer i = 7; b. Integer i = new Integer(5); int j = i; c. byte b = 7;

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

a. True

What is 7 % -4? a. -3 b. 3 c. -4 d. 4

b. 3

Which of the following may appear on the right-hand side of an instance of operator? (Choose all that apply.) a. A reference b. A class c. An interface d. A variable of primitive type e. The name of a primitive type

b. A class c. An interface

The developer can force garbage collection by calling System.gc(). a. True b. False

b. False

The following line of code is valid. int x = 9; byte b = x; a. True b. False

b. False

Suppose ob1 and ob2 are references to instances of java.lang.Object. If (ob1 == ob2) is false, can ob1.equals(ob2) ever be true? a. Yes b. No

b. No

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.

c. The code does not compile.

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 " + 5. ((x > 4) ? 99.99 : 9)); 6. } 7. } 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 5

c. The output: value is 9.0

Given the following code, what keyword must be used at line 4 in order to stop execution of the for loop? boolean b = true; for (;;) { if (b) { <insert code> } // do something } a. stop b. continue c. break d. None of the above

c. break

Which of the following are legal? a. char c = 0x1234; b. char c = \u1234; c. char c = '\u1234';

c. char c = '\u1234';

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. int

What is -50 >> 1? a. A negative number with very large magnitude. b. A positive number with very large magnitude. c. -100 d. -25 e. 100 f. 25

d. -25

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

d. 101

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

d. 3

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.

d. The code does not compile.

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

d. java.text.DateFormat

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

e. public, protected, default, private

Given the following code, and making no other changes, which combination of access modifiers (public, protected, or private) can legally be placed before aMethod() on line 3 and be placed before aMethod() on line 8? 1. class SuperDuper 2. { 3. void aMethod() { } 4. }5. 6. class Sub extends SuperDuper 7. { 8. void aMethod() { } 9. } A. line 3: public; line 8: private B. line 3: protected; line 8: private C. line 3: default; line 8: private D. line 3: private; line 8: protected E. line 3: public; line 8: protected

D. line 3: private; line 8: protected

Which statement is true about this application? 1. class StaticStuff 2{ 3. static int x = 10; 4. 5. static { x += 5; } 6. 7. publicstatic void main(String args[]) 8. { 9. System.out.println("x = " + x); 10. } 11. 12. static {x /= 5; } 13. } A. Lines 5 and 12 will not compile because the method names and return types are missing. B. Line 12 will not compile because you can only have one static initializer. C. The code compiles and execution produces the output x = 10. D. The code compiles and execution produces the output x = 15. E. The code compiles and execution produces the output x = 3.

E. The code compiles and execution produces the output x = 3.

The keyword extends refersa to what type of relationship? a. "is a" b. "has a" c. "was a" d. "will be a" e. None of the above

a. "is a"

What is -8 % 5? a. -3 b. 3 c. -2 d. 2

a. -3

What is the value of x after the following line is executed? x = 32 * (31 - 10 * 3); a. 32 b. 31 c. 3 d. 704 e. None of the above

a. 32

Which of the following may appear on the left-hand side of an instanceof operator? a. A reference b. A class c. An interface d. A variable of primitive type

a. A reference

Choose the valid identifiers from those listed here. (Choose all that apply.) a. BigOlLongStringWithMeaninglessName b. $int c. bytes d. $1 e. finalist

a. BigOlLongStringWithMeaninglessName b. $int c. bytes d. $1 e. finalist

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. By getting a Set object from the Map and iterating through it.

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.

a. Class loading takes no additional time.

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).

a. Garbage collection cannot be forced.

Which statement is true about the following method? int selfXor(int i) { return i ^ i; } a. It always returns 0. b. It always returns 1. c. It always an int where every bit is 1. d. The returned value varies depending on the argument.

a. It always returns 0.

What is the minimal modification that will make this code compile correctly? 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.

a. On line 1, remove the final modifier.

Which of the following expressions are legal? (Choose all that apply.) a. String x = "Hello"; int y = 9; x += y; b. String x = "Hello"; int y = 9; if (x == y) {} c. String x = "Hello"; int y = 9; x = x + y; d. String x = "Hello"; int y = 9; y = y + x;

a. String x = "Hello"; int y = 9; x += y; c. String x = "Hello"; int y = 9; x = x + y;

Given the following code, which of the results that follow would you expect? 1. package mail; 2. interface Box { protected void open(); void close(); public void empty(); } 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.

a. The code will not compile because of line 4.

An abstract class can contain methods with declared bodies. a. True b. False

a. True

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. Vector<Map> v; b. Set<String> s; d. Map<String, String> m;

Is it possible to define a class called Thing so that the following method can return true under certain circumstances? boolean weird(Thing s) { Integer x = new Integer(5); return s.equals(x); } a. Yes b. No

a. Yes

Select the valid primitive data types. (Select all that apply.) a. boolean b. bit c. char d. float e. All of the above

a. boolean c. char d. float

Which of the following declarations are illegal? (Choose all that apply.) a. default String s; b. transient int i = 41; c. public final static native int w(); d. abstract double d; e. abstract final double hyperbolicCosine();

a. default String s; d. abstract double d; e. abstract final double hyperbolicCosine();

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. double d = 1.2d; b. double d = 1.2D;

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;

a. import java.util.Vector; c. import static java.util.Vector.*;

Which of the following expressions results in a positive value in x? a. int x = -1; x = x >>> 5; b. int x = -1; x = x >>> 32; c. byte x = -1; x = x >>> 5; d. int x = -1; x = x >> 5;

a. int x = -1; x = x >>> 5;

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. private readObject

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

a. x[24] is 0 e. x.length is 25

Which of the following statements is true? a. An abstract class may not have any final methods. b. A final class may not have any abstract methods.

b. A final class may not have any abstract methods.

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.

b. Compilation takes slightly more time.

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

b. False

Java arrays always start at index 1. a. True b. False

b. False

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.

b. Primitives are passed by value. d. References are passed by value.

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

b. Static method names c. Static field names

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

b. The output: b contains 5

What does the following code do? Integer i = null; if (i != null & i.intValue() == 5) System.out.println("Value is 5"); a. Prints "Value is 5". b. Throws an exception.

b. Throws an exception.

Which of the following expressions are legal? (Choose all that apply.) a. int x = 6; x = !x; b. int x = 6; if (!(x > 3)) {} c. int x = 6; x = ~x;

b. int x = 6; if (!(x > 3)) {} c. int x = 6; x = ~x;

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. notify()

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) c. public static int main(String [] arg)

b. public static void main(String arg[]) d. public static void main(String[] args)

Which of the following keywords is used to invoke a method in the parent class? a. this b. super c. final d. static

b. super

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

c. 12.3

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 collection.

c. After line 2 executes, the StringBuffer object is eligible for garbage collection.

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.

c. Arguments that are primitive type are passed by value.

Assertions are used to enforce all but which of the following? a. Preconditions b. Postconditions c. Exceptions d. Class invariants

c. Exceptions

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. The code compiles, and prints out >>null<<

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.

c. float

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;

c. int c = 0xabcd; d. int d = 0XABCD;

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. native

After execution of the following code fragment, what are the values of the variables x, a, and b? 1. int x, a = 6, b = 7; 2. x = a++ + b++; a. x = 15, a = 7, b = 8 b. x = 15, a = 6, b = 7 c. x = 13, a = 7, b = 8 d. x = 13, a = 6, b = 7

c. x = 13, a = 7, b = 8

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.

d. "same" will be printed out to the console.

Which of the following operations might throw an ArithmeticException? a. + b. - c. * d. / e. None of these

d. /

How many bits does a float contain? a. 1 b. 8 c. 16 d. 32 e. 64

d. 32

What is the return type of the instanceof operator? a. A reference b. A class c. An int d. A boolean

d. A boolean

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.

d. A final object cannot be reassigned a new address in memory.

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. None of the above

Which of the following operations might throw an ArithmeticException? a. >> b. >>> c. << d. None of these

d. None of these

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

d. Package declaration, imports, class/interface/enum definitions

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. char, int, float, long

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. transient

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

d. −215 through 215 − 1

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

d. −27 through 27 − 1

Which of the following statements is true? a. Transient methods may not be overridden. b. Transient methods must be overridden. c. Transient classes may not be serialized. d. Transient variables must be static. e. Transient variables are not serialized.

e. Transient variables are not serialized.


Conjuntos de estudio relacionados

Behavioral Challenges of Autism reliias

View Set

Kentucky Fact and Info Study Guide

View Set

unit 3 ap classroom micro econ questions

View Set

Chapter 17 'Political culture and the media'

View Set

Psych Videbeck Chapter 6: Therapeutic Communication

View Set

Cyber Security Quizzes 3 & 4 little bit of 7

View Set