Test 2009 Spring Midterm Sample

1 of 26 http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k... Test 2009 Spring Midterm Sample Instructions: Write your name on the e...
Author: Kerry Byrd
1 downloads 0 Views 199KB Size
1 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

Test 2009 Spring Midterm Sample Instructions: Write your name on the examination. DO write on the examination, use it for scratch paper. You will get the examination back with your results. This is a closed book, notes, neighbor examination. Select the best answer. No, it is not a typo, all code appears as intended. Any text in this font is as intended. Do not ask the instructor about any "typos" that is in this font. All output is to be considered what appears in the console. When you have finished the examination, turn in both your answer sheet and the examination. 1. Which of the following statements is true? A. Instance variables have to be assigned a value before use, but local variables do not. B. Local variables have to be assigned a value before use, but instance variables do not. (Correct Answer) C. Both types of variables must be assigned a value before use. D. Neither type of variable must be assigned a value before use. E. None of the above 2. Inside one object, which one of the following could cause an error? A. A function, int create(), and a function string create(). (Correct Answer) B. A function, int create(), and a function string create(string input). C. A function, int create(), and a function int create(int total). D. A function, int create(), and a function int create(string input). E. None of the above 3. True or False? While loops can be nested. A. True (Correct Answer) B. False 4. True or False? A class can implement more than one interface. A. True (Correct Answer) B. False 5. In the class header public class TV. A. public is the access modifier and TV is the name of the class (Correct Answer) B. public is the name of the class and TV is the access modifier 6. True or False? int9 is a valid identifier. A. True (Correct Answer) B. False 7. The accessors are the _________________ methods A. set B. get (Correct Answer) 8. True or False? private fields and methods are part of the inheriting class object. A. True (Correct Answer) B. False 9. What keyword do we use when instantiating an object _________________ A. Create B. = C. new (Correct Answer) D. Object E. is 10. True or False? The conditional operator ?: can be used in expressions A. True (Correct Answer) B. False 11. True or False? A method from a subclass overriding a method from a superclass cannot call the superclass method. A. True B. False (Correct Answer) 12. Which of the following conditional tests is invalid? A. int a = 1;

2/23/2010 8:47 PM

2 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

int b = 10; While (a a){} C. int a = 5; while (a == 5){} D. int a = 5; while (a = 5){} (Correct Answer) E. None of the above 13. Which of the following codes exhibits the correct way of obtaining the length of a string object? A. String s = "Java"; int l = s.size(); B. String s = "Java"; int l = size(s); C. String s = "Java"; int l = length(s); D. String s = "Java"; int l = s.length(); (Correct Answer) E. None of the above 14. Given: 1: public class For { 2: public void test() { 3: for( ; ; ) { 4: System.out.println("Inside the loop"); 5: } 6: } 7: } Will the code block compile? A. Yes B. No 15. Where is memory allocated for objects when they are instantiated? A. On the stack. B. On the heap. (Correct Answer) C. On the stack or the heap depending on how the object is instantiated. D. On the hard drive. E. None of the above 16. How many times will a loop with the for loop header for( i = 1; i = 90, what values would you test your loop with? A. 88 and 89 B. 0 and 90 C. 89, 90 and 91 (Correct Answer) D. 90, 91 and 92 18. True or False? A while loop can be nested inside a for loop and vice-versa. A. True (Correct Answer) B. False 19. Which one of these is not a primitive data type? A. int B. double

2/23/2010 8:47 PM

3 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

C. bool (Correct Answer) D. long E. char 20. integer, Boolean, float numbers are variables of the__________type A. object reference B. PRIMITIVE (Correct Answer) C. STATIC D. PRIMARY E. None of the above 21. To access the number of elements in an array named grades, we use _________________ . A. grades B. grades.size( ) C. grades.size D. grades.length( ) E. grades.length (Correct Answer) 22. Please mark the false statement below. A. A class can have any number of instance variables. B. A method can have many arguments. C. Instance variables should be encapsulated to avoid unwanted/unexpected change in value. D. A method can have more than one return variable. (Correct Answer) E. None of the above 23. In a for loop header, statements are separated with _______. A. Colons B. Commas C. Semi-colons (Correct Answer) D. Preiods 24. When a class implements an interface, _________________ . A. It does not have to implement the abstract methods of the interface. B. It has to implement at least one of the abstract methods of the interface but not all of them. C. It has to implement all of the abstract methods of the interface. (Correct Answer) 25. True or False? abstract methods can be static. A. True B. False (Correct Answer) 26. True or False? abstract methods can be called. A. True B. False (Correct Answer) 27. Let int x=0; int y=++x; int z=x++; After the last instruction is executed, the values of x, y and z are: A. x=1, y=0, z=0 B. x=1, y=0, z=1 C. x=1, y=1, z=0 D. x=2, y=1, z=1 (Correct Answer) E. None of the above 28. JVM stands for: A. Java Virtual Memory B. Job Virtual Machine C. Java Virtual Mode D. Java Veritable Machine E. Java Virtual Machine (Correct Answer) 29. How long is the string returned by the following expression? "Was it a car or a cat I saw?".substring(9, 12) A. It's 2 characters in length B. It's 3 characters in length (Correct Answer) C. It's 4 characters in length D. It's 5 characters in length E. None of the above

2/23/2010 8:47 PM

4 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

30. True or False? char is a valid identifier. A. True B. False (Correct Answer) 31. True or False? We can pass an array parameter to a method. A. True (Correct Answer) B. False 32. What happens if Integer.parseInt() is passed something that's not a number, like "two"? A. Nothing. B. It will throw an exception at runtime. (Correct Answer) C. It will do the best it can to interpret the string passed in and return some kind of integer. D. None of the above 33. True or False? The first index of a String is 1 A. True B. False (Correct Answer) 34. True or False? In a given class, there can be only one constructor. A. True B. False (Correct Answer) 35. What would be appropriate arguments to pass to this function: public static void doStuff(int x, char y) { } A. doStuff(34, "oh"); B. doStuff(3.14159, 'z'); C. doStuff('z', 42); D. doStuff(42, 'z'); (Correct Answer) E. None of the above 36. 1.The name of the Java compiler is: A. java B. javac (Correct Answer) C. compiler D. cc E. jc 37. The conversion from a primitive numeric type to its wrapper class is called _________________ . A. boxing B. unboxing C. autoboxing (Correct Answer) 38. When you use a while loop to count how many values meet a certain condition, you should initialize the variable holding the count to ______ . A. 0 (Correct Answer) B. 1 C. NULL D. There is no need to initialize it 39. True or False? By convention, method names, instance variables and object reference names start with a lower case letter. A. True (Correct Answer) B. False 40. What will be the result of executing the following code? 1: public static void main(String args[]) { 2: char digit = 'a'; 3: for (int i = 0; i < 10; i++) { 4: switch (digit) { 5: case 'x': { 6: int j = 0; 7: System.out.println(j); 8: } 9: default: { 10: int j = 100; 11: System.out.println(j); 12: } 13: } 14: } 15: int i = j;

2/23/2010 8:47 PM

5 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

16: System.out.println(i); 17: } A. 100 will be printed 11 times. B. 100 will be printed 10 times and then there will be a runtime exception. C. The code will not compile because the variable i cannot be declared twice within the main() method. D. The code will not compile because the variable j cannot be declared twice within the switch statement. E. None of the above. (Correct Answer) 41. Why use encapsulation? A. To prevent your instance variables from being set to values that would break your code. B. So that you don't break anyone's code in the future when you need to add more features. C. both A and B (Correct Answer) D. None of the above 42. Assuming the for loop header for( i = 0; i , >=, 0; i--) { if (i % 2 == 0) { System.out.println(i); } } How many numbers are in the output? A. 1 B. 2 C. 5 (Correct Answer) D. 10 E. None of the above 58. True or False? By convention, class names start with a capital letter A. True (Correct Answer) B. False 59. Which of the following is false? A. A static method can access a static variable. B. A Java constant is a variable marked static and final.

2/23/2010 8:47 PM

7 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

C. A static method can be invoked without instantiating the class it is defined in. D. A static variable cannot be accessed by any instantiated objects of that class. (Correct Answer) E. None of the above 60. When class B inherits from class A.... A. A is the superclass and B is the subclass (Correct Answer) B. A is the subclass and B is the superclass 61. How many times will a loop with the for loop header for( i = 0 i < 6; i++ ) execute? A. 1 B. 5 C. 6 (Correct Answer) D. 7 62. True or False? It is possible to have an array of objects. A. True (Correct Answer) B. False 63. True or False? For loops can be nested. A. True (Correct Answer) B. False 64. What is displayed when the following code is compiled and executed? String s1 = new String("Test"); String s2 = new String("Test"); if (s1 == s2) System.out.println("Same"); if (s1.equals(s2)) System.out.println("Equals"); A. Same B. Equals (Correct Answer) C. The code compiles, but nothing is displayed upon execution. D. The code fails to compile. 65. .If you have an if/else if/else code sequence with 4 blocks, what is the minimal number of input values that you should test your code with? A. 1 B. 2 C. 3 D. 4 (Correct Answer) E. 5 66. How many abstract methods must a class have to be classified as an abstract class? A. 2 B. 1 C. 0 or more (Correct Answer) D. 3 or more E. None of the above 67. True or False? The body of a while loop always executes at least once. A. True B. False (Correct Answer) 68. What is the out put of the program below?

public class HiClass { public static void main (String[] args){ System.out.print("Hi"); System.out.println(" cis"); System.out.print("class!"); }

2/23/2010 8:47 PM

8 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

} A. Hi cis class! B. Hi cis class! (Correct Answer) C. Hicisclass D. Hicis class E. None of the above 69. The rock class has a method "void doNothing()". The pebble class extends rock and has a method "int doNothing(int windVelocity)". Is this a valid method override? A. Yes B. No, you are not allowed to change the argument list C. No, you are not allowed to change the return type D. No, but it is a valid method overload (Correct Answer) E. None of the above 70. What is output when you attempt to compile and run the following code? public class ScopeTest { static int x = 2; public static void main(String[] args) { int x = 10; ScopeTest s = new ScopeTest(); s.x++; System.out.println(x); ScopeTest.showint(2); System.out.println(x); s.x++; s.showint(1); } public static void showint(int a) { System.out.println(x); } } A. 10 2 10 4 B. 10 3 10 4 (Correct Answer) C. 10 3 10 3 D. It won't compile because the second declaration of int x in main is illegal. E. None of the above 71. True or False? The conditional operator ?: has lower precedence that the = operator A. True B. False (Correct Answer) 72. True or False? We can instantiate an object from an abstract class. A. True B. False (Correct Answer) 73. True or False? When we use a while loop, we always know in advance how many times the loop body will be executed. A. True B. False (Correct Answer) 74. True or False? We cannot combine the declaration and instantiation of an array. A. True B. False (Correct Answer) 75. What will be output when you attempt to compile and run the following code? class Base { int i = 99; public void amethod() { System.out.println("Base.amethod()");

2/23/2010 8:47 PM

9 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

} Base() { amethod(); } } public class Derived extends Base { int i = -1; public static void main(String argv[]) { Base b = new Derived(); System.out.println(b.i); b.amethod(); } public void amethod() { System.out.println("Derived.amethod()"); } } A. Derived.amethod() -1 Derived.amethod() B. Derived.amethod() 99 Derived.amethod() (Correct Answer) C. 99 Derived.amethod() D. Base.amethod() 99 Derived.amethod() E. Compile time error 76. If you have a derived class constructor that does not have an argument, how do you call its base-class constructor that has an argument? A. Create an instance of the base class in the derived class's constructor. B. Use the super keyword and the appropriate argument list. (Correct Answer) C. Pass the argument to the constructor of the derived class and the compiler will pass it on to the base class. D. You're out of luck. E. None of the above 77. To access the element at index i of an array named grades, we use _________________ . A. grades B. grades[ i ] (Correct Answer) C. grades( i ) D. grades{ i } 78. True or False? In a for loop, we usually (although not always) use a loop control variable for counting. A. True (Correct Answer) B. False 79. True or False? public fields and methods are inherited. A. True (Correct Answer) B. False 80. True or False? Curly braces around a for loop body are optional if the for loop body consists of only one statement. A. True (Correct Answer) B. False 81. True or False? = is the equality operator. A. True B. False (Correct Answer) 82. True or False? A variable that is declared inside the true (or false) block of an if statement is still in scope after we exit that block. A. True B. False (Correct Answer) 83. True or False? String is in the java.string package A. True B. False (Correct Answer) 84. True or False? Inside an if statement, statements inside the true block must be indented, otherwise the code will not compile A. True

2/23/2010 8:47 PM

10 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

B. False (Correct Answer) 85. True or False? If a class has an abstract method, then that class is automatically an interface. A. True B. False (Correct Answer) 86. True or False? Mutator methods are void methods. A. True (Correct Answer) B. False 87. What does the dot operator (.) do? A. It is used to set the decimal point an integer. B. It is used to access the methods and variables of objects. (Correct Answer) C. It is used to mark the end of a statement. D. It is used to separate names in a file (example: Hello.World.Doc) E. None of the above 88. There must be 1 class with "main" method. This class must be of type A. public, like "public class" (Correct Answer) B. private, like "private class" C. extend, like "extend class" D. regular, like "class" E. None of the above 89. What is the output of this code sequence? String word = "Java"; System.out.println( word.charAt( 1 ) ); A. J B. a (Correct Answer) C. v D. " E. None of the above 90. Which of the following is the correct way of making a constant in java? A. static int i = 10; B. static final int i = 10; (Correct Answer) C. const int i = 10; D. final int i = 10; E. None of the above 91. True or False? When comparing objects for equality, we typically use the == operator A. True B. False (Correct Answer) 92. Which statement will not generate an error? A. float offset = 42.3f; (Correct Answer) B. char letter = "great"; C. int books = "a"; D. boolean istrue = 346; E. None of the above 93. True or False? a && b is true only when both a and b are true A. True (Correct Answer) B. False 94. True or False? An interface can contain a constructor. A. True B. False (Correct Answer) 95. Which of the following is a data type? A. Byte B. Void C. Float D. Both A and C (Correct Answer) E. None of the above 96. Which of the following is an enhanced loop? A. for (int i = 0; i < 12; i++) {} B. while (i < 0) {}

2/23/2010 8:47 PM

11 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

C. for (int numbers : numberArray) {} (Correct Answer) D. All of these E. None of the above 97. What is the output of the following program? public class Output { public static void main(String[] args) { Output o = new Output(); o.go(); } public void go() { int i = 3; int t = 0; for (int j = 3; j < 20; j++) { t = j; if (j % i == 0) System.out.print(--t + " "); else System.out.print(t++ + " "); } } } A. B. C. D. E.

4 4 5 7 7 8 10 10 11 13 13 14 16 16 17 19 19 2 4 5 5 7 8 8 10 11 11 13 14 14 16 17 17 19 (Correct Answer) 4 3 4 7 6 7 10 9 10 13 12 13 16 15 16 19 18 2 5 6 5 8 9 8 11 12 11 14 15 14 17 18 17 20 None of the above

98. True or False? An interface can contain one or more static constants. A. True (Correct Answer) B. False 99. What will happen when you attempt to compile and run this code? class Base { public final void amethod() { System.out.println("amethod"); } } public class Fin extends Base { public static void main(String argv[]) { Base b = new Base(); b.amethod(); } } A. Compile time error indicating that a class with any final methods must be declared final itself B. Compile time error indicating that you cannot inherit from a class with final methods C. Run time error indicating that Base is not defined as final D. Success in compilation and output of "amethod" at run time. (Correct Answer) E. None of the above 100. Consider the following code: public class A { public final boolean foo(int a, double b) { // do stuff } } Which of the following statements is true? A. The following method B.foo(...) overrides the A.foo(...) method. public class B extends A { public int foo(int a, double b) { // do stuff } } B. The following method C.foo(...) overrides the A.foo(...) method. public class C extends A { public boolean foo(int a, double b) { // do stuff } } C. The following method D.foo(...) overloads the A.foo(...) method. public class D extends A {

2/23/2010 8:47 PM

12 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

public int foo(int a, double b) { // do stuff } } D. The following method E.foo(...) overloads the A.foo(...) method. public class E extends A { public int foo(double b) { // do stuff } } (Correct Answer) E. None of the above 101. What is a class ? A. A group of objects B. A source for objects C. A blueprint to create object (Correct Answer) D. All above E. None of the above 102. What Java keyword do we use in the constructor of a class inheriting from another class if we want to call the constructor of the base class? A. call B. super (Correct Answer) C. constructor D. clone 103. What is the output of this code sequence? String word = "Java"; System.out.println( word.length( ) ); A. 0 B. 1 C. 4 (Correct Answer) D. 5 E. None of the above 104. What will happen when you attempt to compile and run the following code? public static void main(String[] args) { int Output = 10; boolean b1 = false; if ((b1 == true) && ((Output += 10) == 20)) { System.out.println("We are equal " + Output); } else { System.out.println("Not equal! " + Output); } } A. Compilation error, attempting to perform binary comparison on logical data type. B. Compilation and output of "We are equal 10". C. Compilation and output of "Not equal! 20". (Correct Answer) D. Compilation and output of "Not equal! 10". E. None of the above 105. Instance variables are stored on the.... A. heap (Correct Answer) B. stack C. register D. ROM E. None of the above 106. The StringBuilder and StringBuffer classes A. provide a mutable character sequence. B. are better at manipulating strings than the String class. C. have the same interface. D. all of the above. (Correct Answer) E. None of the above 107. True or False? An interface can contain instance variables. A. True B. False (Correct Answer) 108. What will happen when you attempt to compile and run the following code

2/23/2010 8:47 PM

13 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

public class As { int i = 10; int j; char z = 1; boolean b; public static void main(String argv[]) { As a = new As(); a.amethod(); } public void amethod() { System.out.println(j); System.out.println(b); } } A. Compilation succeeds and at run time an output of 0 and false (Correct Answer) B. Compilation succeeds and at run time an output of 0 and true C. Compile time error - b is not initialized D. Compile time error - z must be assigned a char value E. None of the above 109. True or False? The default constructor takes no parameter. A. True (Correct Answer) B. False 110. What is the signature of the main method? A. public static int main(String[] args) B. public static void main(String args) C. public static void main(String[] args) (Correct Answer) D. public static int main(String args) E. None of the above 111. When computing the maximum value in an array of integers, you should intialize the maximum value to _________________. A. 0 B. 1 C. the first element in the array (Correct Answer) D. 100 112. Which of the following statements will result in a compiler error? A. int _x = 7; B. int 3x = 7; (Correct Answer) C. int $x = 7; D. int x3 = 7; E. None of the above 113. True or False? Inside the block of a switch statement, the break statements are optional A. True (Correct Answer) B. False 114. How many times will a loop with the for loop header for( i = 5; i 33 ) System.out.print( 1 ); else System.out.print( 2 ); System.out.println( 3 ); A. 1 B. 2 C. 12 D. 123 E. 23 (Correct Answer) 154. What will happen when you attempt to compile and run the following code? abstract class Employee { String name; public abstract float calcIncome(); } class Manager extends Employee { public void hire(String who) { System.out.println( who + " hired by " + name ); } public void fire(String who) { System.out.println( who + " fired by " + name ); } } public class ManagerCheck { public static void main(String args[]) { Manager me = new Manager(); me.hire("newbie"); me.fire("nobody"); } } A. who hired by name and who fired by name B. newbie hired by name and nobody fired by name C. newbie hired by null and nobody fired by null D. Compilations fails (Correct Answer) 155. What is a benefit of object-oriented programming? A. The ability to quickly expand on existing code B. The ability to reuse code easily and often C. The ability to extend existing code without having to touch production code D. All of the above (Correct Answer) E. None of the above 156. Given this code: int a = 2; int b = 3; int c; c = (a + b) * 2 - b / 3; What is the value of c? A. 4 B. 6 C. 8 D. 9 (Correct Answer) E. None of the above 157. When you use a while loop to compute the sum of several values, you should initialize the variables holding the sum to ______ . A. 0 (Correct Answer) B. 1 C. NULL D. There is no need to initialize it 158. A javadoc comment ends with ________. A. // B. /* C. /**

2/23/2010 8:47 PM

19 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

D. */ (Correct Answer) 159. True or False? Accessor methods take no parameter. A. True (Correct Answer) B. False 160. The Java language and libraries from Sun Microsystems are: A. available for a low cost to students B. cannot be used without a run time license fee C. free and can be downloaded at http://java.sun.com (Correct Answer) D. are supported only on Microsoft XP E. None of the above 161. Which of the following options will run the PropertyCheck class and produce the output SCJA? public class PropertyCheck { public static void main(String args[]) { String myprop = System.getProperty("myprop"); System.out.println(myprop); } } A. java -Dmyprop = SCJA PropertyCheck B. java PropertyCheck -Dmyprop=SCJA C. java -Dmyprop=SCJA PropertyCheck (Correct Answer) D. java - Dmyprop=SCJA PropertyCheck E. java -Dmyprop=SCJA PropertyCheck.class 162. True or False? When using an if/else if structure, we can only use one else if block A. True B. False (Correct Answer) 163. What is the initial capacity of the following StringBuilder? StringBuilder sb = new StringBuilder("Able was I ere I saw Elba."); A. It's the length of the initial string : 26. B. It's the length of the initial string + 8: 26 + 8 = 34. C. It's the length of the initial string + 16: 26 + 16 = 42. (Correct Answer) D. It's the length of the initial string + 32: 26 + 32 = 58. E. None of the above 164. What keyword do you use in order to be able to use a Java class inside a program? A. include B. class C. import (Correct Answer) D. package E. with 165. True or False? Methods defined in a Java interface are public and abstract by default. A. True. (Correct Answer) B. False. 166. True or False? Mutator methods take no parameter. A. True B. False (Correct Answer) 167. What is the difference between a for loop and a while loop? A. A for loop cannot use a boolean test. B. A for loop cannot be used inside a while loop. C. A while loop only has a boolean test. (Correct Answer) D. They are the same. E. None of the above 168. What results from attempting to compile and run the following code? public class Ternary { public static void main(String args[]) { int a = 5; System.out.println("Value is - " + ((a < 5) ? 9.9 : 9)); } } A. Prints: Value is - 9

2/23/2010 8:47 PM

20 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

B. Prints: Value is - 5 C. Compilation error D. None of these (Correct Answer) 169. Assuming the for loop header for( i = 0; i < 20; i++ ), what will be value of i after we exit the loop? A. 0 B. 19 C. 20 (Correct Answer) D. 21 170. True or False? The naming convention for constants (final static variables) is to make the name all uppercase. A. True (Correct Answer) B. False 171. True or False? if statements can be nested A. True (Correct Answer) B. False 172. True or False? When calling the constructor of a superclass from the constructor of the subclass, the call to that superclass constructor must be the first statement in the subclass constructor. A. True (Correct Answer) B. False 173. How many "return" statements can a method have? A. none B. only one C. two D. many (Correct Answer) E. None of the above 174. True or False? Java is a high-level language. A. True (Correct Answer) B. False 175. Where is the error in the array declaration int [5] numbers; A. There is no error B. The square brackets should be empty (Correct Answer) C. There should be no space between int and [ D. It should be int numbers[5]; 176. True or False? When computing the maximum value among a number of values, we should initialize the maximum to 0. A. True B. False (Correct Answer) 177. Which of these is not a primitive type in Java? A. Int B. Float C. Tall (Correct Answer) D. Short E. None of the above 178. True or False? tax Rate is a valid identifier. A. True B. False (Correct Answer) 179. True or False? When an object reference is first declared, its value is null. A. True (Correct Answer) B. False 180. A javadoc comment starts with ________. A. // B. /* C. /** (Correct Answer) D. */ 181. True or False? Curly braces around the loop body are optional if the loop body consists of only one statement. A. True (Correct Answer) B. False

2/23/2010 8:47 PM

21 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

182. True or False? && and || have the same level of precedence. A. True B. False (Correct Answer) 183. True or False? Overriding a method and overloading a method means the same thing. A. True B. False (Correct Answer) 184. True or False? An abstract class cannot be extended. A. True B. False (Correct Answer) 185. What keyword do we use in the class header that inherits from another class? A. inherits B. extends (Correct Answer) C. protected D. modifies 186. a final variable means... A. its the result of a math equation. B. its the last value of the program. C. the value can't be changed. (Correct Answer) D. it can only be changed through using methods. E. None of the above 187. The data type of the return value of the toString method is A. Object B. boolean C. String (Correct Answer) D. class 188. Whats wrong with this statement.

int [] my_array = new int[10]; my_array[10] = 5; A. The array needs to be initialized first. B. There is a conversion problem. C. The index is beyond the array size (Correct Answer) D. my_array is a reserved name in Java. E. None of the above 189. True or False? private fields and methods are inherited. A. True B. False (Correct Answer) 190. The result of (double) 3 / 2 is A. 1.0 B. 1.5 (Correct Answer) C. 3.0 D. 2.0 E. 0.0 191. True or False? If a class has an abstract method, then that class is automatically abstract. A. True (Correct Answer) B. False 192. True or False? When using an if/else if structure, it is mandatory to have an else block A. True B. False (Correct Answer) 193. True or False? a || b is true only when either a or b is true but not both a and b are true. A. True B. False (Correct Answer) 194. What are Instance Variables? A. Variables found under main().

2/23/2010 8:47 PM

22 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

B. C. D. E.

An object's data. (Correct Answer) any boolean value. An object's method None of the above

195. True or False? A while loop can be used for counting input values that have a certain property, for instance positive values A. True (Correct Answer) B. False 196. what value does a reference variable have, when it is not referencing to any object? A. 0 B. 1 C. null (Correct Answer) D. random number E. None of the above 197. True or False? Usually, an abstract class contains at least one abstract method. A. True (Correct Answer) B. False 198. The switch statement can be used instead of an if/else if statement. A. always B. only when comparing the value of an expression to a floating point value C. only when comparing the value of an expression to a char or integer variable D. only when comparing the value of an expression to a char or integer constant (Correct Answer) E. only when comparing the value of an expression to a String value 199. Polymorphism means _______. A. One form only B. Two forms only C. Multiple forms (Correct Answer) D. No form 200. What is the concatenation operator? A. . B. + C. concat 201. Which of the following expresses the condition: a is less than b and c? A. a < b || a < c B. a < b && c C. a < b && a < c (Correct Answer) 202. In the instance variable declaration private int value; A. private is the access modifier, int is the name of the instance variable, and value is the data type B. private is the name of the instance variable, int is the data type, and value is the access modifier C. private is the access modifier, int is the data type, and value is the name of the instance variable (Correct Answer) D. private is the data type, int is the access modifier, and value is the name of the instance variable 203. The Creator of Java is? A. Dennis M Ritchie B. James Gosling (Correct Answer) C. Bruce Eckel D. Brian W. Kernighan E. None of the above 204. True or False? The length method of the String class takes no argument and returns an int A. True (Correct Answer) B. False 205. !( a A. B. C. D. E.

> 3 ) is equivalent to _________________ . a < 3 a j is false i < k is true j == k is false i == k is true B. i > j is true i < k is true j == k is true i == k is false C. i > j is false i < k is false j == k is true i == k is false D. i > j is false i < k is false j == k is false i == k is true (Correct Answer) E. None of the above 210. True or False? When declaring an array, we use a set of square brackets. A. True (Correct Answer) B. False 211. A plain array is different than ArrayList because...? A. It isn't different. B. A plain array doesn't need to know the size of the array when it is created but the ArrayList does. C. The ArrayList doesn't need to know the size of the array when it is created but the plain array does. (Correct Answer) D. An ArrayList cannot accept a size when created. E. None of the above 212. True or False? abstract methods can be overridden. A. True (Correct Answer) B. False 213. Which statements will NOT compile? A. long foo = 15; int bar = foo; (Correct Answer) B. int foo = 15; int[] bar = new int[7]; bar[0] = foo; C. Dog fido = new Dog(); Dog rover = new Dog(); rover = fido; D. Dog[] kennel = new Dog[7]; E. None of the above 214. True or False? When asking the user for an integer value, it is possible that the user enters a character that is not an

2/23/2010 8:47 PM

24 of 26

http://dpearson-lenovo:9105/index.php?action=exam_questions&test_k...

integer; using a while loop, we can keep asking the user for an integer until the user enters one. A. True (Correct Answer) B. False 215. The data type of the return value of the equals method is A. Object B. boolean (Correct Answer) C. equals D. class 216. True or False? helloWorld is a valid identifier. A. True (Correct Answer) B. False 217. Assume that class A extends class B, which extends class C. Also all the three classes implement the method test(). How can a method in a class A invoke the test() method defined in class C (without creating a new instance of class C). A. super.test(); B. super.super.test(); C. ::test(); D. C.test(); E. It is not possible to invoke test() method defined in C from a method in A. (Correct Answer) 218. !( a A. B. C. D. E.

> 38 && b