PRO192

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

C

16. What are the legal types for whatsMyType? short s = 10; whatsMyType = !s; A. short B. int C. There are no possible legal types.

C

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

D

16. Which of the following operations might throw an ArithmeticException? A. + B. - C. * D. / E. None of these

B

17. True or false: If class Y extends class X, the two classes are in different packages, and class X has a protected method called abby(), then any instance of Y may call the abby() method of any other instance of Y. A. True B. False

D

17. What is the return type of the instanceof operator? A. A reference B. A class C. An int D. A boolean

D

17. When a negative long is cast to a byte, what are the possible values of the result? A. Positive B. Zero C. Negative D. All of the above

A

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

C

18. When a negative byte is cast to a long, what are the possible values of the result? A. Positive B. Zero C. Negative

C

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

A

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

D

18. Which of the following statements are true? A. A final class must be instantiated. B. A final class must contain at least one final method. C. A final class must contain at least one final data field. D. A final class may not be extended. 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).

E

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

A, C, D

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

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.

C

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

D

12. Which of the following may legally appear as the new type (between the parentheses) in a cast operation? A. Abstract classes B. Final classes C. Primitives D. All of the above

F

12. Which of the following statements are true? A. An abstract class may be instantiated. B. An abstract class must contain at least one abstract method. C. An abstract class must contain at least one abstract data field. D. An abstract class must be overridden. E. An abstract class must declare that it implements an interface. F. None of the above.

A

13. Suppose the declared type of x is a class, and the declared type of y is an interface. When is the assignment x = y; legal? A. When the type of x is Object B. When the type of x is an array C. Always D. Never

C

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

A, C

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

A

14. Suppose the type of xarr is an array of XXX, and the type of yarr is an array of YYY. When is the assignment xarr = yarr; legal? A. Sometimes B. Always C. Never

A

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

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

B

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

15. Which of the following operations might throw an ArithmeticException? A. >> B. >>> C. << D. None of these

D

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.

C

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

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.

A

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

D

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

A

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

A

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

D

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

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

B

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

C

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

B

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

D

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.

B

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

C

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

B

10. Consider the following code: 1. Raccoon rocky; 2. SwampThing pogo; 3. Washer w; 4. 5. rocky = new Raccoon(); 6. w = rocky; 7. pogo = w; Which of the following statements is true? (Choose one.) A. Line 6 will not compile; an explicit cast is required to convert a Raccoon to a Washer. B. Line 7 will not compile; an explicit cast is required to convert a Washer to a SwampThing. C. The code will compile and run. D. The code will compile but will throw an exception at line 7, because runtime conversion from an interface to a class is not permitted. E. The code will compile but will throw an exception at line 7, because the runtime class of w cannot be converted to type SwampThing.

A

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

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

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.

B

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

D

11. Which of the following may legally appear as the new type (between the parentheses) in a cast operation? A. Classes B. Interfaces C. Arrays of classes D. Arrays of interfaces 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 collection

A, B

19. Which of the following may appear on the right-hand side of an instanceof operator? (Choose 2) A. A reference B. A class C. An interface D. A variable of primitive type E. The name of a primitive type

A, B, E

19. Which of the following operators can perform promotion on their operands? (Choose all that apply.) A. + B. - C. ++ D. -- E. ~ F. !

D

19. Which of the following statements are true? A. A final class must be instantiated. B. A final class may only contain final methods. C. A final class may not contain non-final data fields. D. A final class may not be extended. E. None of the above.

F

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

B, C

2. Which of the following expressions are legal? (Choose 2) A. int x = 6; x = !x; B. int x = 6; if (!(x > 3)) {} C. int x = 6; x = ~x;

B

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

D

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

D

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

A

20. What is the difference between the rules for method-call conversion and the rules for assignment conversion? 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.

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

A, B, C

25. Which of the following code snippets compile? (choose 3) 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

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

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.

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.

A

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

3. 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;

B, C

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

D

8. Consider the following code: 1. Dog rover, fido; 2. Animal anim; 3. 4. rover = new Dog(); 5. anim = rover; 6. fido = (Dog)anim; Which of the following statements is true? (Choose one.) A. Line 5 will not compile. B. Line 6 will not compile. C. The code will compile but will throw an exception at line 6. D. The code will compile and run. E. The code will compile and run, but the cast in line 6 is not required and can be eliminated.

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

E

4. In the following code, what are the possible types for variable result? (Choose the most complete true answer.) 1. byte b = 11; 2. short s = 13; 3. result = b * ++s; A. byte, short, int, long, float, double B. boolean, byte, short, char, int, long, float, double C. byte, short, char, int, long, float, double D. byte, short, char E. int, long, float, double

A, C

4. Which of the following expressions are legal? (Choose 2) 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;

E

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

D

5. Consider the following class: 1. class Cruncher { 2. void crunch(int i) { 3. System.out.println("int version"); 4. } 5. void crunch(String s) { 6. System.out.println("String version"); 7. } 8. 9. public static void main(String args[]) { 10. Cruncher crun = new Cruncher(); 11. char ch = 'p'; 12. crun.crunch(ch); 13. } 14. } Which of the following statements is true? (Choose one.) A. Line 5 will not compile, because void methods cannot be overridden. B. Line 12 will not compile, because no version of crunch() takes a char argument. C. The code will compile but will throw an exception at line 12. D. The code will compile and produce the following output: int version. E. The code will compile and produce the following output: String version.

A, E

5. Consider the following line of code: int[] x = new int[25]; After execution, which statements are true? (Choose 2) 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

5. What is -8 % 5? A. -3 B. 3 C. -2 D. 2

E

5. Which statement is true about this application? 1. class StaticStuff 2 { 3. static int x = 10; 4. 5. static { x += 5; } 6. 7. public static 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.

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

B

6. What is 7 % -4? A. -3 B. 3 C. -4 D. 4

D

6. Which of the following statements is true? (Choose one.) A. Object references can be converted in assignments but not in method calls. B. Object references can be converted in method calls but not in assignments. C. Object references can be converted in both method calls and assignments, but the rules governing these conversions are very different. D. Object references can be converted in both method calls and assignments, and the rules governing these conversions are identical. E. Object references can never be converted.

E

6. Which statement is true about this code? 1. class HasStatic 2. { 3. private static int x = 100; 4. 5. public static void main(String args[]) 6. { 7. HasStatic hs1 = new HasStatic(); 8. hs1.x++; 9. HasStatic hs2 = new HasStatic(); 10. hs2.x++; 11. hs1 = new HasStatic(); 12. hs1.x++; 13. HasStatic.x++; 14. System.out.println("x = " + x); 15. } 16. } A. Line 8 will not compile because it is a static reference to a private variable. B. Line 13 will not compile because it is a static reference to a private variable. C. The program compiles and the output is x = 102. D. The program compiles and the output is x = 103. E. The program compiles and the output is x = 104.

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

C

7. Consider the following code. Which line will not compile? 1. Object ob = new Object(); 2. String[] stringarr = new String[50]; 3. Float floater = new Float(3.14f); 4. ob = stringarr; 5. ob = stringarr[5]; 6. floater = ob; 7. ob = floater; A. Line 4 B. Line 5 C. Line 6 D. Line 7

D

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

B

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

C

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

D

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

E

9. Consider the following code: 1. Cat sunflower; 2. Washer wawa; 3. SwampThing pogo; 4. 5. sunflower = new Cat(); 6. wawa = sunflower; 7. pogo = (SwampThing)wawa; Which of the following statements is true? (Choose one.) A. Line 6 will not compile; an explicit cast is required to convert a Cat to a Washer. B. Line 7 will not compile, because you cannot cast an interface to a class. C. The code will compile and run, but the cast in line 7 is not required and can be eliminated. D. The code will compile but will throw an exception at line 7, because runtime conversion from an interface to a class is not permitted. E. The code will compile but will throw an exception at line 7, because the runtime class of wawa cannot be converted to type SwampThing.

C

9. This question concerns the following class definition: 1. package abcde; 2. 3. public class Bird { 4. protected static int referenceCount = 0; 5. public Bird() { referenceCount++; } 6. protected void fly() { /* Flap wings, etc. */ } 7. static int getRefCount() { return referenceCount; } 8. } Which statement is true about class Bird and the following class Parrot? 1. package abcde; 2. 3. class Parrot extends abcde.Bird { 4. public void fly() { 5. /* Parrot-specific flight code. */ 6. } 7. public int getRefCount() { 8. return referenceCount; 9. } 10. } A. Compilation of Parrot.java fails at line 4 because method fly() is protected in the superclass, and classes Bird and Parrot are in the same package. B. Compilation of Parrot.java fails at line 4 because method fly() is protected in the superclass and public in the subclass, and methods may not be overridden to be more public. C. Compilation of Parrot.java fails at line 7 because method getRefCount() is static in the superclass, and static methods may not be overridden to be nonstatic. D. Compilation of Parrot.java succeeds, but a runtime exception is thrown if method fly() is ever called on an instance of class Parrot. E. Compilation of Parrot.java succeeds, but a runtime exception is thrown if method getRefCount() is ever called on an instance of class Parrot.

B

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

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

A

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

A

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

C

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

B

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

A

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

This question concerns the following class definition: 1. package abcde; 2. 3. public class Bird { 4. protected static int referenceCount = 0; 5. public Bird() { referenceCount++; } 6. protected void fly() { /* Flap wings, etc. */ } 7. static int getRefCount() { return referenceCount; } 8. } Which statement is true about class Bird and the following class Nightingale? 1. package singers; 2. 3. class Nightingale extends abcde.Bird { 4. Nightingale() { referenceCount++; } 5. 6. public static void main(String args[]) { 7. System.out.print("Before: " + referenceCount); 8. Nightingale florence = new Nightingale(); 9. System.out.println(" After: " + referenceCount); 10. florence.fly(); 11. } 12. } A. The program will compile and execute. The output will be Before: 0 After: 2. B. The program will compile and execute. The output will be Before: 0 After: 1. C. Compilation of Nightingale will fail at line 4 because static members cannot be overridden. D. Compilation of Nightingale will fail at line 10 because method fly() is protected in the superclass. E. Compilation of Nightingale will succeed, but an exception will be thrown at line 10, because method fly() is protected in the superclass.


Kaugnay na mga set ng pag-aaral

7 випадків уживання ТИРЕ: типове завдання ЗНО на відповідності 👍

View Set

Quiz 10 Organ Donation and Transplantation

View Set