why do I bother when I'm gonna kms anyway

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

54. Mandy designs a Student object that includes a name, address and gpa. This is an example of ___. a. data encapsulation b. data operations c. top-down software design d. abstraction

A

63. Which is true? a. A testbench should only print messages when a test case fails b. A testbench should test all possible values c. Calling every method once ensures 100% code coverage d. Passing all test cases ensures a program is bug free

A

66. Which is true? public class Car { XXX Person theDriver = new Person(); theDriver.getDriver( ); } a. Class Carusesa Person b. Class Personusesa Car c. XXX should be replaced withpublic d. XXX should be replaced withprivate

A

68. Select the default constructor signature for a Student class. a. public Student( ) b. public void Student( ) c. private void Student( ) d. private Student( )

A

72. Select the signature for a helper method that calculates the student's GPA. public class Student { private double myGPA; . . .} a. private void calcGPA( ) b. public void calcGPA( ) c. private calcGPA( ) d. private int calcGPA( )

A

85. What is output? int cost = Integer.valueOf("1999"); Double myScore = 30.8; int yourScore = myScore.intValue(); System.out.println(cost + " " + yourScore); a. 1999 30 b. 1999 30.0 c. 1999 31 d. Error: incompatible types

A

92. The keyword this___. a. Implicitly refers to an object within instance methods b. Can not be used within a constructor c. Can not be used within instance methods d. Should be avoided when a field member and method parameter share the same name

A

A method is...

A predefined set of instructions in a class

Return types can be...

Objects Primitive data types

A characteristic of a class definition that is not shared by its objects

static

159. Given an array with values 5, 10, 15, 20, 25, what are the fewest number of swaps needed to reverse the list? a. 2 b. 3 c. 4 d. 5

A

87. Which comparison should not be used? Integer score1 = 20; Integer score2 = 30; int score3 = 40; a. score1 < score2 b. b. score1 >= score3 c. score2 == score3 d. score1 == score2

D

2. In calcArea(), width and height are _____ public static void calcArea(int width, int height){}; a. arguments b. statements c. parameters d. method names

C

21. Which line has an error? 1 public static int computeSumOfSquares(int num1, int num2) { 2 int sum; 3 sum = (num1 * num1) + (num2 * num2); 4 return;5 } a. Line 1 b. Line 3 c. Line 4 d. None of the lines contains an error

C

69. Which is true? a. A field can not be initialized in the field declaration b. A default constructor has at least one parameter c. A constructor has no return type d. The Java compilter does not initalize fields to their default values

C

71. Which is true? a. Private members can be accessed by a class user b. A mutator is also known as a getter method c. A mutator may change class fields d. An accessor is also known as a setter method

C

An instance field can be...

A primitive data type Another object

26. What is the output? public static int changeValue(int x) { int y; x = x * 2; y = x + 1; return y; } public static void main(String args[]) { int a; a = 5; System.out.print("a = " + a + ", result = " + changeValue(a)); } a. a = 5, result = 6 b. a = 5, result = 11 c. a = 10, result = 11 d. Error: Cannot assign parameter x

B

29. Which method is called? p = processData(9.5, 2.3); a. public static int processData (double num, int x){...}; b. public static int processData (double num, double x){...}; d. Both methods could be called, resulting in a compiler error

B

A constructor...

Allows an instance of the class to be created

What is an object?

An instance of a class

Java is...

An object oriented programming language

1. Which method name is not valid? a. calcAverage() b. calc Average() c. _calcAvg() d. calc_average()

B

102. To maintain a list is descending sorted order, a new item must be inserted ___ a. directly after the first element that is smaller than the item b. directly before the first element that is smaller than the item c. At the front of the list d. directly after the first element that is smaller than the item

B

104. What does mystery( ) do? void mystery(ArrayList<Integer> nums, int target) { int i; int count; count = 0; for(i = 0; i < nums.size(); ++i) { if(nums.get(i) < target) { ++count; } } return count; } a. Returns the number of elements in the ArrayList due to a logic error b. Returns the number of elements less than target c. Always returns zero due to a logic error d. Returns the index of the first element less than target

B

108. Given a programmer-defined class called Person, what is output? Person barb = new Person(18); Person jessie = new Person(21); change(barb, jessie); System.out.println(barb.getAge()); public static void change(Person p1, Person p2) { p1 = p2; } a. The memory location of barb b. 18 c. 21 d. Error: null pointer exception

B

113. What is output? public class DayEnd { static void timeHour(int hours) { int timeLeft; try { if (hours > 23) { throw new Exception("Invalid Hour!"); } timeLeft = 24 - hours; System.out.println("Time Left: "+timeLeft); } catch (Exception except) { System.out.println("Oops"); System.out.println(excpt.getMessage()); } } public static void main(String[] args) { timeHour(23); } } a. Invalid Hour! Time Left: 0 b. Error!Invalid Hour! c. Error!Invalid Hour!Time Left: 0 d. Invalid Hour!Error!

B

119. What is output? public class Summation { public static int sum(int arr[]) { int result = 0; int i; for (i = 0; i <= arr.length; i++) { result = result + arr[i]; } return result; } public static void main(String[] args) { int list[] = {1,3,4,5}; try { System.out.println("Sum of given array is " + sum(list)); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Array Index is Out Of Bounds"); } catch (IndexOutOfBoundsException except) { System.out.println("Index is Out Of Bounds"); } } } a. Array Index is Out Of BoundsIndex is Out Of Bounds b. Array Index is Out Of Bounds c. Index is Out Of Bounds d. Index is Out Of BoundsArray Index is Out Of Bounds

B

99. Which XXX completes countProbation( ) to return the number of students with a GPA below parameter lowGrade? public class Roster { private ArrayList<Student> studentList; public int countProbation(double lowGrade) { int count = 0; for(int i = 0; i < studentList.size(); ++i) { Student s = studentList.get(i); if (XXX < lowGrade) { ++count; } } return count; } } a. studentList.getGPA() b. s.getGPA() c. getGPA() d. s

B

101. What does mystery( ) do? void mystery(ArrayList<Integer> nums, int target) { int i; for(i = 0; i < nums.size(); ++i) { if(nums.get(i) == target) { nums.remove(i); } } } a. Removes only the first occurrence of target b. Results in an index out of bounds error c. Removes every occurence of target d. Nothing, since the for loop is always skipped

C

164. Which statement declares a two-dimensional integer array called myArray with 3 rows and 4 columns? a. int myArray[3, 4]; b. int[] myArray = new int[7]; c. int[][] myArray = new int[3][4]; d. int[] myArray = new int[4][3];

C

5. Which list correctly defines three parameters of type int, double and String for createRecord()? public static void createRecord(. . .){}; a. (int num, int cost, int name) b. (num, cost, name) c. (int num, double cost, String name) d. (17, 12.34, "Janet")

C

51. What is the likely purpose of someMethod() based on the signature? int someMethod(int[] nums) a. Create a new array b. Modify the array contents c. Calculate a value based on the array contents d. Make a copy of the array

C

53. A reasonable abstraction for a car includes: a. an engine b. car color c. driving d. number of miles driven

C

How do you create an object?

ClassName variableName = new ClassName();

Code inside the main method is...

Compiled and executed

Use upper camel case for...

Constructor names Class names

10. Select the true statement. a. A benefit of methods is to increase redundant code b. A key reason for including methods is to make main() run faster c. Method stubs can not be compiled d. Method stubs are temporary placeholders used during development

D

105. Which calls increment() from outside class Inventory? public class Inventory { public static void increment() { ... }; } a. increment(); b. Inventory widgets = new Inventory();widgets.increment(); c. A static method can not be called from outside the class d. Inventory.increment();

D

109. Which is true? Integer cost = 15; int quantity = 20; a. Variables cost and quantity store memory locations b. cost stores the value 15 c. quantity is a reference variable d. cost stores an object location

D

115. What is output? public class FindPerimeter { public static int perimeter(int arr[]) { int perimeter = 0; int i; for (i = 0; i < arr.length; i++) { perimeter += arr[i]; } return perimeter; } public static void main(String[] args) { int sides[] = {1,3,4,5}; try { System.out.println("Perimeter for given sides is " + perimeter(sides)); } catch (Exception except) { System.out.println("Caught Exception: " + excpt.getMessage()); } finally { System.out.println("End"); } } } a. Perimeter for given sides is 13 b. End c. Error: The catch block is missing d. Perimeter for given sides is 13End

D

118. Which is the correct code to declare a catch-all handler? a. catch (Exception excpt) {...} b. catch (AllException excpt) {...} c. catch (Throw excpt) {...} d. catch (Throwable excpt) {...}

D

157. Given x = 4 and y = 8, what are the ending values of x and y? x = y;y = x;x = y; a. x = 4, y = 4 b. x = 4, y = 8 c. x = 8, y = 4 d. x = 8, y = 8

D

165. How many elements are in the array? int[][] userVals = new int[2][4]; a. 2 b. 4 c. 6 d. 8

D

How do you add instance fields to a class

public ClassName { fieldType fieldName; }

How do you write a constructor?

public ClassName() { }

Construction parameters allow you to...

Set starting values for instace fields

Void means that...

The method dosen't return anything

If there is a return type on a method...

The method has to return a value of that type

A template for a new type of object

class

A special method that initalizes the instance variables of a newly-constructed object

constructor

To show that a class inherits from another class use the _________ keyword

extends

An attribute of an object; non-static variable defined at the class level

instance

This is the act of creating an object

instantiation

These control the behavior of a program

method

These have identity, state, and behavior

object

Which is not a type of primitive data

object

A way of organizing code and data into objects, rather than independent methods

object oriented

How do you write a method?

public returnType methodName() { }

How do you add prarameters to a method?

public void method(parameterType parameter) { }

A method that returns a value

value

How do you call a method on an object

object.Name.methodName();

7. How many items are returned from printValues()? public static void printValues(int a, int b){. . .} a. 0 b. 1 c. 2 d. 3

A

94. How many objects are created? Dog labrador = new Dog(); Dog poodle; Dog beagle = new Dog(); poodle = beagle; a. 2 b. 3 c. 4 d. Error: Null pointer exception

A

93. Which XXX calls the alternative constructor? public class Student { private double myGPA; private int id; public Student(double gpa) { myGPA = gpa; } public Student() { id = 0; XXX } } a. this( ) b. Student(0.0); c. Student.this(0.0); d. this(0.0);

D

97. Which XXX adds a student to the ArrayList? public class Roster { private ArrayList<Student> studentList; public void addStudent(Student s) { XXX; } } a. studentList = s; b. addStudent(s) c. add(s); d. studentList.add(s);

D

98. What does mystery( ) do? public class Roster { private ArrayList<Student> list; public Student mystery() { Student student1 = list.get(0); double gpa = student1.getGPA(); for(int i = 1; i < list.size(); ++i) { Student s = list.get(i); if(s.getGPA() > gpa) { student1 = s; } } return student1; } } a. Always returns the first student in the roster b. Returns the student with the lowest GPA c. Sorts the student list by GPA d. Returns the student with the hightest GPA

D

100. Which is true? a. A LinkedList offers faster element insertion than an ArrayList b. A List implements the LinkedList interface c. A LinkedList implements the ArrayList interface d. A LinkedList offers faster positional access than an ArrayList

A

111. Which is true? a. Reference variables store memory locations b. Instances of programmer-defined objects are immutable c. An instance of String stores data rather than an object reference d. Contents of a Double instance can be modified after initialization

A

117. Which of the following statements is true? a. IOException handles file-reading and file-closing exceptions b. The compiler closes a file once it encounters an error and terminates the program c. A finally block is executed only if a program encounters an error d. IOException closes the file stream during exception handling

A

121. Which syntax defines a throws clause for exceptions that are not handled within a method? a. public static void myMethod() throws Exception {...} b. public static void myMethod() {...} c. public static Exception void myMethod(){...} d. public static void myMethod(throws Exception){...}

A

133. What is the error inwriteFile( )? public static void writeFile() throws IOException { FileOutputStream foStream = null; PrintWriter outFS = null; foStream = new FileOutputStream(); outFS = new PrintWriter(foStream); outFS.println("Java is my favorite language!"); outFS.flush(); foStream.close(); } a. The output stream has not been properly opened b. writeFile( ) should throw PrintException c. outFS has not been closed d. foStream has not been flushed

A

137. Which XXX insertsuserItemintoswuntil the user enters "Quit"? StringWriter sw = new StringWriter();PrintWriter pw = new PrintWriter(sw); System.out.println("Enter items (type Exit to quit):"); String userItem = scnr.next(); while (!userItem.equals("Quit")) { XXX userItem = scnr.next(); } System.out.println(sw.toString()); a. pw.print(userItem); b. pw.add(userItem); c. sw = sw + userItem d. sw.add(userItem);

A

139. What is returned by System.in.read() when data is no longer available? a. -1 b. any negative value c. EOF d. \0x

A

146. Which XXX / YYY declare an array having MAX_SIZE elements and initializes all elements with -1? final int MAX_SIZE = 4; int[] myNumbers = new int[XXX]; int i; for (i = 0; i < YYY; ++i) { myNumbers[i] = -1; } a. MAX_SIZE / MAX_SIZE b. MAX_SIZE / MAX_SIZE - 1 c. MAX_SIZE - 1 / MAX_SIZE d. MAX_SIZE - 1 / MAX_SIZE - 1

A

158. What code for XXX, YYY correctly swaps a and b? Choices are written as XXX / YYY. XXX; a = b; YYY; b = tmp; a. tmp = a / (nothing) b. tmp = a / tmp = b c. tmp = b / (nothing) d. (nothing) / tmp = a

A

126. Given the following list of sorted elements, how many elements of the list will be checked to find 25 using binary search? {12, 13, 15, 20, 23, 24, 25, 36, 40} a. 3 b. 2 c. 7 d. 8

B

120. What is output? public class Division { public static double division(double a, double b) throws Exception { if(b == 0) throw new Exception("Invalid number."); return a / b; } public static void main(String[] args) { try { System.out.println("Result: " + division(5, 0)); } catch (ArithmeticException e) { System.out.println("Arithmetic Exception Error"); } catch (Exception except) { System.out.println("Division by Zero"); } catch(Throwable thrwObj) { System.out.println("Error"); } } } a. Arithmetic Exception ErrorDivision by ZeroError b. Division by Zero c. Arithmetic Exception Error d. Error

B

123. What is output? public class MathOps { public static int divOp(int num, int denom) throws Exception { if (denom == 0) { throw new Exception("Invalid div input"); } return num / denom; } public static double sqrtOp(double num) throws Exception { if (num < 0) { throw new Exception("Invalid sqrt input"); } return Math.sqrt(num); } public static void main(String[] args) { try { int x; int y; x = 4; y = 0; System.out.println(divOp(x, y)); System.out.println(sqrtOp((double)y)); } catch (Exception except) { System.out.println(excpt.getMessage()); System.out.println("Cannot compute operation"); } } } a. Invalid div inputInvalid sqrt input b. Invalid div inputCannot compute operation c. Invalid div inputInvalid sqrt inputCannot compute operation d. Cannot compute operation

B

127. What XXX will generate the following output? Enter a value: 0 was not found. public class BinarySearch { public static int binarySearch(int [] list, int listSize, int key) { int mid; int low; int high; low = 0; high = listSize - 1; while (high >= low) { mid = (high + low) / 2; if (list[mid] < key) { low = mid + 1; } else if (list[mid] > key) { high = mid - 1; } else { return XXX; } } return -1; } public static void main(String [] args) { Scanner scnr = new Scanner(System.in); int [] list = {2, 4, 7, 10, 11, 32, 45, 87}; final int listSize = 8; int i; int key; int keyIndex; System.out.print("Enter a value: "); key = scnr.nextInt(); keyIndex = binarySearch(list, listSize, key); if (keyIndex == -1) { System.out.println(key + " was not found."); } else { System.out.println("Found " + key + " at index " + keyIndex + "."); } } } a.low b. mid c. high d. -1

B

128. For the list {Allen, Barry, Christopher, Daisy, Garry, Sandy, Zac}, what is the second name searched when the list is searched for Garry using binary search? a. Barry b. Sandy c. Garry d. Christopher

B

130. Which XXX will generate the following output? LIST 3 5 8 11 12 33 46 88 Enter a value: 0 was no St found. public class LinearSearch { public static int linearSearch(int [] list, int listSize, int key) { int i; for (i = 0; i < listSize; ++i) { if (list[i] == key) { return i; } } return XXX; } public static void main(String [] args) { Scanner scnr = new Scanner(System.in); int [] list = { 3, 5, 8, 11, 12, 33, 46, 88 }; final int LIST_SIZE = 8; int i; int key; int keyIndex; System.out.print("LIST "); for (i = 0; i < LIST_SIZE; ++i) { System.out.print(list[i] + " "); } System.out.println(); System.out.print("Enter a value: "); key = scnr.nextInt(); keyIndex = linearSearch(list, LIST_SIZE, key); if (keyIndex == -1) { System.out.println(key + " was not found."); } else { System.out.println("Found " + key + " at index " + keyIndex + "."); } } } a. 1 b. -1 c. 0 d. 2

B

136. Which statement copies the contents ofswtouserInput? StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("Java is awesome!"); String userInput; a. userInput = pw b. userInput = sw.toString(); c. userInput = sw; d. userInput = pw.print();

B

141. What is the index of the last element? int numList[50]; a. 0 b. 49 c. 50 d. Unknown, because the array has not been initialized.

B

142. What is the ending value of the element at index 0? int numbers[10]; numbers[0] = 35; numbers[1] = 37; numbers[1] = numbers[0] + 4; a. 0 b. 35 c. 37 d. 39

B

148. Which assigns the array's last element with 99? int[] myVector = new int[15]; a. myVector[0] = 99; b. myVector[14] = 99; c. myVector[15] = 99; d. myVector[16] = 99;

B

152. The numNegatives variable counts the number of negative values in the array userVals. What should numNegatives be initialized to? int[] userVals = new int[20]; int i; numNegatives = XXX; for (i = 0; i < 20; ++i) { if (userValues[i] < 0) { numNegatives = numNegatives + 1; } } a. No initialization needed b. 0 c. -1 d. userVals[0]

B

160. Given that integer array x has elements 4, 7, 3, 0, 8, what are the elements after the loop? int i; for (i = 0; i < 4; ++i) { x[i] = x[i + 1]; } a. 4, 4, 7, 3, 0 b. 7, 3, 0, 8, 8 c. 7, 3, 0, 8, 4 d. Error: Invalid access

B

35. What is output? char[] emotion = {'h','a','p','p','y'}; System.out.print(emotion[4]); a. 4 b. y c. happy d. p

B

49. What is the likely purpose of someMethod() based on the signature? void someMethod(int[] nums, int value) a. Create a new array b. Change all array elements tovalue c. Return the number of timesvalueoccurs in the array d. Make a copy of the array

B

70. Which XXX is the proper default constructor? public class Employee { private double mySalary; XXX } a. public Employee(double salary) { mySalary = salary; } b. public Employee( ) { mySalary = 10000; } c. public Employee( ) { double mySalary = 10000; } d. private Employee( ) { mySalary = 10000; }

B

73. Which is true? a. A private helper method can be called by a class user b. A private helper method can call public methods in the same class c. A private helper method can not call other private methods in the same class d. A private helper method can be called from main( ) in another class

B

77. Which XXX method signature returns the student's GPA? public class Student { private double myGPA; private int myID; XXX return myGPA; } } a. private double getGPA( ) b. public double getGPA( ) c. public int getGPA( ) d. double getGPA( )

B

80. What is the size of groceryList after the code segment? ArrayList<String> groceryList;groceryList = new ArrayList<String>(); groceryList.add("Bread"); groceryList.add("Apples"); groceryList.add("Grape Jelly"); groceryList.add("Peanut Butter"); groceryList.set(1, "Frozen Pizza"); a. 3 b. 4 c. 5 d. Error: index out of bounds

B

82. What is output? ArrayList<Integer> numList = new ArrayList<Integer>(); int count; for(count = 1; count < 10; ++count) { numList.add(count); } System.out.println(numList.get(4)); a. 4 b. 5 c. 6 d. Error: index out of bounds

B

90. Which is a primitive type? a. Character b. Boolean c. String d. Integer

B

91. Which XXX assigns the parameter to the instance member? public class Student { private double gpa; public void setGPA(double gpa) { XXX } } a. this = gpa b. this.gpa = gpa; c. double gpa = this.gpa; d. gpa = this.gpa;

B

96. How many references are declared? Dog labrador = new Dog(); Dog poodle; Dog beagle = new Dog(); poodle = beagle; poodle = labrador; a. 2 b. 3 c. 4 d. Error: illegal assignment statement

B

103. Which element is stored at index 1afterthe following sequence? ArrayList<String> groceryList; groceryList = new ArrayList<String(); groceryList.add("Bread"); groceryList.add("Apples"); groceryList.add("Grape Jelly"); groceryList.add(1,"Peanut Butter"); groceryList.set(1, "Frozen Pizza"); groceryList.remove(1); a. Bread b. Peanut Butter c. Apples d. Frozen Pizza

C

106. What is output? Item jar = new Item(); Item ball = new Item(); System.out.println(Item.count); public class Item { public static int count = 1; public Item() { count++; } } a. 1 b. 2 c. 3 d. Error: syntax error

C

107. A static field ___. a. is also called an instance variable b. is initialized in the constructor c. has global scope d. is accessed using an object name such as objectName.fieldName

C

110. Given a programmer-defined class called Person, what is output? Person barb = new Person(18); Person jessie = new Person(21);change(barb, jessie); System.out.println(barb.getAge()); public static void change(Person p1, Person p2) { int age = p2.getAge(); p1.setAge(age); } a. The memory location of barb b. 18 c. 21 d. Error: null pointer exception

C

112. Which construct is the exception handler? try { if (val < 0) { throw new Exception("Error!"); } } catch (exceptionType excpt) { System.out.println(excpt.getMessage()); } a. try {...} b. throw new Exception (...) c. catch {...} d. exceptionType excptObj

C

114. What is output? public class BaggageWeight { static void baggageWeight(int weight) { boolean value = false; try { while (!value) { if (weight > 30) { throw new Exception("Double Max Weight"); } if (weight > 15) { throw new Exception("Excess Weight"); } value = true; System.out.println("Accepted"); } } catch (Exception except) { System.out.println(excpt.getMessage()); } } public static void main(String[] args) { baggageWeight(42); } } a. Accepted b. Double Max WeightAccepted c. Double Max Weight c. Double Max Weight Excess Weight

C

116. Which XXX defines a finally block to close a file? public class FileReadChars { public static void main(String[] args) { FileReader fileReader = null; String fileName; int charRead; charRead = 0; fileName = "file.txt"; try { System.out.println("Opening file " + fileName + "."); fileReader = new FileReader(fileName); System.out.print("Reading character values: "); while (charRead != -1) { charRead = fileReader.read; System.out.print(charRead + " "); } System.out.println(); } catch (IOException excpt) { System.out.println("Caught IOException: " + excpt.getMessage()); } finally { try { XXX } catch (IOException except) { System.out.println("Caught IOException: " + excpt.getMessage()); } } } } a. fileReader.close(); b. if (fileReader == null) { fileReader.close(); } c. if (fileReader != null) { fileReader.close(); } d. close(fileReader);

C

122. Which catch syntax handles the unchecked exception, ArithmeticException? a. catch (Exception except) b. catch (Exception ArithmeticException except) c. catch (ArithmeticException except) d. catch (Exception ArithmeticException)

C

124. Which unchecked exception catches the error in the given code snippet? Object x = new Integer(0); System.out.println((String) x); a. NullPointerException b. UnknownEntityException c. ClassCastException d. ArithmeticException

C

125. What is output? public class StringLength { public static void lengthFun(String str) { int length = str.length(); System.out.println("Length : " + length); } public static void main(String[] args) { try { String str = null; lengthFun(str); } catch (Exception except) { System.out.println(except); } } } a. null b. 4 c. java.lang.NullPointerException d. java.lang.ArithmeticException

C

129. For the list {12, 15, 13, 20, 23, 27, 25, 36, 40}, how many elements will be compared to find 25 using linear search? a. 6 b. 2 c. 7 d. 3

C

132. Which is true? a. The FileOutputStream class includes println( ) b. A PrintWriter object should be closed using close( ) c. A PrintWriter constructor requires an OutputStream object d. A FileOutputStream object opens an existing file

C

134. What is output given the user input? >3 blind mice System.out.print("Enter info: "); Scanner keyboard = new Scanner(System.in); String info = keyboard.nextLine(); Scanner inputScnr = new Scanner(info); int item1 = inputScnr.nextInt(); String item2 = inputScnr.next(); String item3 = inputScnr.next(); System.out.println(item3 + " " + item1); a. blind mice 3 b. 3 blind mice c. mice 3 d. Error: input mismatch exception

C

140. Given an array scorePerQuiz has 10 elements. Which assigns element 7 with the value 8? a. scorePerQuiz = 8; b. scorePerQuiz[0] = 8; c. scorePerQuiz[7] = 8; d. scorePerQuiz[8] = 7;

C

145. Which is an invalid access for the array? int[] numsList = new int[5];int x = 3; a. numsList[x-3] b. numsList[0] c. numsList[x+2] d. numsList[(2*x) - x]

C

147. Which assigns the array's first element with 99? int[] myVector = new int[4]; a. myVector[] = 99; b. myVector[-1] = 99; c. myVector[0] = 99; d. myVector[1] = 99;

C

153. Which best describes what is output? Assume v is a large array of ints. int i; int s; s = v[0]; for (i = 0; i < N_SIZE; ++i) { if (s > v[i]) { s = v[i]; } } System.out.println(s); a. first value in v b. max value in v c. min value in v d. last value in v

C

154. Given two arrays, studentNames that maintains a list of student names, and studentScores that has a list of the scores for each student, which XXX and YYY prints out only the student names whose score is above 80? Choices are in the form XXX / YYY. String[] studentNames = new String[NUM_STUDENTS]; int[] studentScores = new int[NUM_STUDENTS]; int i; for (i = 0; i < NUM_STUDENTS; ++i) { if (XXX > 80) { System.out.print(YYY + " "); } } a. studentNames[i] / studentNames[i] b. studentNames[i] / studentScores[i] c. studentScores[i] / studentNames[i] d. studentScores[i] / studentScores[i]

C

155. Two arrays, itemsNames and itemsPrices, are used to store a list of item names and their corresponding prices. Which is true? a. Using two arrays saves memory versus using one array. b. Both arrays should be of the same data type. c. Both arrays should be declared to have the same number of elements. d. The item names should appear in both arrays.

C

166. Which XXX and YYY will find the minimum value of all the elements in the array? Choices are in the form XXX / YYY. int[][] userVals = new int[NUM_ROWS][NUM_COLS]; minVal = userVals[0][0]; for (i = 0; i < NUM_ROWS; ++i) { for (j = 0; j < NUM_COLS; ++j) { if (XXX) { YYY; } } } a. userVals[i] < minVal / minVal = userVals[i] b. userVals[j] < minVal / minVal = userVals[j] c. userVals[i][j] < minVal / minVal = userVals[i][j] d. userVals[i][j] > minVal / minVal = userVals[i][j]

C

167. Which XXX and YYY correctly complete the code to find the maximum score? Choices are in the form XXX / YYY. int[] scores = {43, 24, 58, 92, 60, 72}; int maxScore;maxScore = scores[0]; for (XXX) { if (num > maxScore) { YYY; } } a. int scores: num / maxScore = num b. scores != 0 / num = maxScore c. int num: scores / maxScore = num d. num < scores / num = maxScore

C

168. Which regular loop corresponds to this enhanced for loop? char[] vowels = {'a', 'e', 'i', 'o', 'u'}; for (char item: vowels) { System.out.println(item); } a. for (int i = 0; i < item; ++i) { System.out.println(vowels[i]); } b. for (int i = 0; i < item.length; ++i) { System.out.println(vowels[i]); } c. for (int i = 0; i < vowels.length; ++i) { System.out.println(vowels[i]); } d. for (int i = 0; i < vowels.length; ++i) { System.out.println(item[i]); }

C

78. Insert XXX to output the student's ID. public class Student { private double myGPA; private int myID; . . . public getID( ) { return myID; } public static void main(String [] args) { Student s = new Student(); XXX } } a. System.out.println("Student ID: " + getID( )); b. System.out.println("Student ID: "); c. System.out.println("Student ID: " + s.getID( )); d. System.out.println("Student ID: " + student.getID( ));

C

81. Which replaces "Apples" with "Bananas"? ArrayList<String> groceryList;groceryList = new ArrayList<String>(); groceryList.add("Bread"); groceryList.add("Apples"); groceryList.add("Grape Jelly"); a. groceryList.set(2, "Bananas"); b. groceryList.replace(1, "Bananas"); c. groceryList.set(1, "Bananas"); d. groceryList.replace("Apples", "Bananas");

C

83. Which lines demonstrate autoboxing? 1 Integer intValue = 20; 2 double myScore = 30.0; 3 Double yourScore = myScore; 4 Character yourGrade = 'A'; 5 char myGrade = yourGrade; a. 2, 5 b. 3, 5 c. 1, 3, 4 d. 1, 2, 3, 4, 5

C

84. Autobaxing is _____. a. the automatic conversion of wrapper class objects to the corresponding primitive types b. the use of a static method to convert a Double to an Integer c. the automatic conversion of primitive types to the corresponding wrapper classes d. the use of a static method to convert a String to an integer

C

88. What is stored in score1, score2, and grade? Integer score1 = 72; int score2 = 85; Character grade = 'C'; a. 72, 85, C b. obj reference, obj reference, C c. obj reference, 85, obj reference d. obj reference, obj reference, obj reference

C

95. Which is true? a. A reference variable contains data rather than a memory address b. The new operator is used to declare a reference c. A reference declaration and object creation can be combined in a single statement d. Three references can not refer to the same object

C

131. Which XXX allows information to be written to a file using print( )? FileOutputStream foStream = null; PrintWriter outFS = null; foStream = new FileOutputStream("outfile.txt"); XXXoutFS.println("Java is my favorite language!"); a. outFS = new PrintWriter("outfile.txt"); b. new PrintWriter(foStream); c. outFS = PrintWriter.open(foStream); d. outFS = new PrintWriter(foStream);

D

135. What is output given the user input? >three blind mice System.out.print("Enter info: "); Scanner keyboard = new Scanner(System.in); String info = keyboard.nextLine(); Scanner inputScnr = new Scanner(info); int item1 = inputScnr.nextInt(); String item2 = inputScnr.next(); String item3 = inputScnr.next(); System.out.println(item1 + " " + item2 + " " + item1); a. mice blind three b. three blind mice c. three three three d. Error: input mismatch exception

D

138. Which is true? a. A program mustimport java.io.systemto use System.out b. System.output.print() only outputs objects of type String c. The output of println() for an object reference includes all data stored in the object d. Data written to System.out are placed in a buffer and eventually output

D

143. What is the ending value of the element at index 1? int numbers[10]; //Changenumbers[0] = 35; numbers[1] = 37; numbers[1] = numbers[0] + 4; a. 0 b. 35 c. 37 d. 39

D

144. How many elements does the array declaration create? int[] scores = new int[10]; scores[0] = 25; scores[1] = 22; scores[2] = 18; scores[3] = 28; a. 0 b. 4 c. 9 d. 10

D

149. What are the ending contents of the array? Choices show elements in index order 0, 1, 2. int[] yearsList = new int[3]; yearsList[0] = 5; yearsList[1] = yearsList[0]; yearsList[0] = 10; yearsList[2] = yearsList[1]; a. 5, 5, 5 b. 5, 10, 10 c. 10, 10, 10 d. 10, 5, 5

D

150. Which XXX and YYY correctly output the smallest values? Array userVals contains 100 elements that are integers (which may be positive or negative). Choices are in the form XXX / YYY. // Determine smallest (min) valueint minVal; XXX for (i = 0; i < 100; ++i) { if (YYY) { minVal = userVals[i]; } } System.out.println("Min: " + minVal); a. minVal = 0; / userVal > minVal b. minVal = 0; / userVal < minVal c. minVal = userVals[0]; / userVals[i] > minVal d. minVal = userVals[0]; / userVals[i] < minVal

D

151. The following program generates an error. Why? final int NUM_ELEMENTS = 5; int[] userVals = new int[NUM_ELEMENTS]; int i; userVals[0] = 1; userVals[1] = 7; userVals[2] = 4; for (i = 0; i <= userVals.length; ++i) { System.out.println(userVals[i]); } a. Variable i is never initialized. b. The array userVals has 5 elements, but only 3 have values assigned. c. The integer NUM_ELEMENTS is declared as a constant d. The for loop tries to access an index that is out of the array's valid range.

D

156. Given two arrays, which code will output all the arrays' elements, in the order key, item followed by a newline? int[] keysList = new int[SIZE_LIST]; int[] itemsList = new int[SIZE_LIST]; a. System.out.println(keysList[SIZE_LIST - 1] + ", " + itemsList[SIZE_LIST - 1]); b. System.out.println(keysList[SIZE_LIST] + ", " + itemsList[SIZE_LIST]); c. for (i = 0; i < SIZE_LIST - 1; ++i) { System.out.println(keysList[i] + ", " + itemsList[i]); d. for (i = 0; i < SIZE_LIST; ++i) { System.out.println(keysList[i] + ", " + itemsList[i]); }

D

161. Given that integer array x has elements 5, 10, 15, 20, what is the output? int i; for (i = 0; i < 4; ++i) { System.out.print(x[i] + x[i + 1]); } a. 10, 15, 20, 5 b. 15, 25, 35, 25 c. 15, 25, 35, 20 d. Error: Invalid access

D

162. Given two integer arrays prevValues and newValues. Which code copies the array prevValues into newValues? The size of both arrays is NUM_ELEMENTS. a. newValues = prevValues; b. newValues[] = prevValues[]; c. newValues[NUM_ELEMENTS] = prevValues[NUM_ELEMENTS]; d. for (i = 0; i < NUM_ELEMENTS; ++i) { newVals[i] = prevVals[i];}

D

163. Given two integer arrays, largerArray with 4 elements, and smallerArray with 3 elements. What is the result after this code executes? for (i = 0; i < 4; ++i) { largerArray[i] = smallerArray[i]; } a. All the elements of largerArray will get copied to smallerArray. b. Some of the elements of largerArray will get copied to smallerArray. c. All of the elements of smallerArray will get copied to largerArray. d. Error: The two arrays are not the same size.

D

169. The enhanced for loop _____ a. reduces the number of iterations necessary to visit all elements of an array b. can be used to replace any regular for loop while yielding less code c. creates a copy of an existing array and iterates through the copy's elements d. prevents incorrectly accessing elements outside of an array's range

D

74. Select mutator XXX to set the temperature. public class WeatherData { private double myTemp; XXX } a. public void setTemp() { myTemp = 92.6; } b. private void setTemp(double temp) { myTemp = temp; } c. public void setTemp(int temp) { myTemp = temp; } d. public void setTemp(double temp) { myTemp = temp; }

D

75. Which XXX declares a student's name public class Student { XXX private double myGPA; private int myID; public int getID( ) { return myID; } } a. String myName; b. public String myName; c. private myName; d. private String myName;

D

76. What is output? public class Student { private double myGPA; private int myCredits; public void increaseCredits(int amount) { myCredits = myCredits + amount; } public void setCredits(int credits) { myCredits = credits; } public int getCredits() { return myCredits; } public static void main(String [] args) { Student s = new Student(); s.setCredits(6); s.increaseCredits(12); System.out.println(s.getCredits()); } } a. 0 b. 6 c. 12 d. 18

D

79. Which accesses the number of elements in groceryList? ArrayList <String> groceryList;groceryList = new ArrayList<String>(); a. groceryList.size b. groceryList.length c. groceryList.length( ) d. groceryList.size( )

D

86. Select all lines that demonstrate unboxing. 1 Integer intValue = Integer.valueOf("1999"); 2 Double myScore = 30.2; 3 int yourScore = myScore.intValue(); 4 Character yourGrade = 'A'; 5 char myGrade = yourGrade; a. 1, 2, 4 b. 1, 3 c. 3 d. 5

D

89. Which comparison will evaluate as true? Integer score1 = 130; Integer score2 = 130; int score3 = 140; a. score1 == score2 b. score1 >= score3 c. score2 == score3 d. None

D

36. Which is not a good use of a perfect size array? a. university student IDs b. names of the week c. names of the months d. names of marker colors in a box of 8

A

39. Which is true for the declaration of anoversizearray that records daily sales for any month? int MAX_DAYS = 31; int[] dailySales = new int[MAX_DAYS]; int dailySalesSize = 0; a. MAX_DAYS should be constant b. dailySalesSize should be declared as double c. MAX_DAYS should be assignes 365 d. dailySalesSize should be assignes MAX_DAYS

A

A class is...

Like a blueprint for objects

24. Which is true regarding how methods work? a. After a method returns, its local variables keep their values, which serve as their initial values the next time the method is called b. A method's local variables are discarded upon a method's return; each new call creates new local variables in memory c. A return address indicates the value returned by the method d. If a method returns a variable, the method stores the variable's value until the method is called again

B

25. What is the output? public static void swapValues(int x, int y) { int tmp; tmp = x; x = y; y = tmp; } public static void main(String args[]) { int p = 4, q = 3; swapValues(p, q); System.out.print("p = " + p + ", q = " + q); } a. p = 3, q = 3 b. p = 4, q = 3 c. p = 3, q = 4 d. Error: Argument names must match parameter names

B

31. What is the output when calling printName("Juan", 19)? public static void printName(String name, int id) { System.out.print(name + " ID: " + id); } public static void printName(int id) { System.out.print("Name" + " ID: " + id); } public static void printName(String name, int id, int age) { System.out.print(name + " ID: " + id + " age: " + age); } a. Juan ID: 19 age: 19 b. Juan ID: 19 c. Name ID: 19 d. There is no output

B

38. Which XXX completes this method that adds a note to an oversized array of notes? public static void addNote(String[] allNotes, int numNotes, String newNote) { allNotes[numNotes] = newNote; XXX } a. --numNotes; b. ++numNotes; c. no additional statement needed d. ++allNotes;

B

40. Which is the best capacity for anoversizearray that records daily phone sales during a month. Maximum number of sales for a single day is 100. a. 30 b. 31 c. 99 d. 100

B

42. What is the content of array ages after calling shift()? public static void shift(int[] nums) { int i; for(i = 0; i < nums.length-1; ++i) { nums[i] = nums[i+1]; } } public static void main(String[] args) { int[] ages = {16, 19, 24, 17}; shift(ages); } a. {16, 19, 24, 17} b. {19, 24, 17, 17} c. (19, 24, 17, 16) d. {16, 16, 19, 24}

B

48. The frequency() method is supposed to return the number of occurrences of target within the array.Identify the location of any errors. public static int[] frequency(int[] nums, int target) { int index; int count = 0; for(index = 0; index < nums.length; ++index) { if(nums[index] == target) { ++count; } } return count; } a. The code has no errors b. Only the method signature has an error c. Only the method body has errors d. Both the method signature and body have errors

B

6. How many items are returned from calcAverage()? public static int calcAverage(int a, int b, int c){. . .} a. 0 b. 1 c. 2 d. 3

B

62. What is the value of hondaAccord's odometer at the end of main( )? public class SimpleCar { private int odometer; public SimpleCar() { odometer = 0; } public SimpleCar(int miles) { odometer = miles; } public void drive(int miles) { odometer = odometer + miles; } public static void main(String[] args) { SimpleCar fordFusion = new SimpleCar(); SimpleCar hondaAccord = new SimpleCar(30); fordFusion.drive(100); fordFusion.drive(20); } } a. 20 b. 30 c. 100 d. 120

B

Use lower camel case for...

Variable names

55. ___ means to have a user interact with an item at a high-level. a. Data encapsulation b. Information hiding c. User interaction design d. Abstraction

D

Where are details in the class saved?

In instance fields

How do you call a method that uses parameters?

objectName.methodName(parameterValue);

56. How many objects of type Car are created? Car mustang = new Car();Car prius;int miles;Truck tundra = new Truck(); a. 0 b. 1 c. 2 d. 3

B

23. While performing main(), what is the value of tripleValue at XXX? public static int tripleTheValue(int val) { int tripleValue; tripleValue = val * 3; return tripleValue; } public static void main(String args[]) { int result; result = tripleTheValue(4); XXX } a. not defined b. 4 c. 3 d. 12

A

3. Which statement correctly calls calcArea() with two int arguments? a. calcArea(4, 12); b. public void calcArea(int w, int h); c. calcArea(int w, int h); d. calcArea( );

A

30. What is the output when calling printName("Juan", 429, 19)? public static void printName(String name, int id) { System.out.print(name + " ID: " + id); } public static void printName(int id) { System.out.print("Name" + " ID: " + id); } public static void printName(String name, int id, int age) { System.out.print(name + " ID: " + id + " age: " + age); } a. Juan ID: 429 age: 19 b. Juan ID: 429 c. There is no output d. Name ID: 19 age: 429

A

43. What is output? public static void swap(int val1, int val2) { int temp; temp = val1; val1 = val2; val2 = temp; } public static void main(String[] args) { int x; int y; x = 10; y = 20; swap(x, y); System.out.println(x + ", " + y); } a. 10, 20 b. 20, 20 c. 10, 10 d. 20, 10

A

47. What is copiedNums' length after the code segment? int[] originalNums = {1,2,3,4,5}; int[] copiedNums; copy(originalNums, 3); public static int[] copy(int[] nums, int changeAmt) { int[] modifiedNums = new int[nums.length * changeAmt]; int index; for(index = 0; index < nums.length; ++index) { modifiedNums[index] = nums[index]; } return modifiedNums; } a. null b. 0 c. 5 d. 15

A

52. The frequency() method is supposed to return the number of occurrences of target within the array.Identify the location of any errors. public static int frequency(int[] nums, int target) { int index; int count = 0; for(index = 0; index < nums.length; ++index) { if(nums[index] == target) { ++count; } } return count; } a. The code has no errors b. Only the method signature has an error c. Only the method body has errors d. Both the method signature and body have errors

A

12. How does using findMax() improve the code? public static int findMax(int val1, int val2) { int max; if(val1 > val2) { max = val1; } else { max = val2; } return max; } public static void main(String args[]) { int max1; int max2; int max3; max1 = findMax(15, 7); max2 = findMax(100, 101); max3 = findMax(20, 30); } a. Using findMax() makes main() run faster b. Using findMax() decreases redundant code c. Using findMax() reduces the number of variables d. Using findMax() does not improve the code

B

14. For the given program, how many print statements will execute? public static void printShippingCharge(double weight) { if((weight > 0.0) && (weight <= 10.0)) { System.out.println(weight * 0.75); } else if((weight > 10.0) && (weight <= 15.0)) { System.out.println(itemWeight * 0.85); } else if((weight > 15.0) && (weight <= 20.0)) { System.out.println(itemWeight * 0.95); } } public static void main(String args[]) { printShippingCharge(18); printShippingCharge(6); printShippingCharge(25); } a. 1 b. 2 c. 3 d. 9

B

65. What is output? public class UnitTest { public int square(int value) { return value * 1; } public static void main(String[] args) { UnitTest testObject = new UnitTest(); if(testObject.square(3) != 9) { System.out.println("Error: square(3)"); } if(testObject.square(1) != 1) { System.out.println("Error: square(1)"); } if(testObject.square(-1) != 1) { System.out.println("Error: square(-1)"); } System.out.println("Tests complete."); } } } a. Error: square(3)Error: square(1)Error: square(-1)Tests complete. b. Error: square(3)Error: square(-1)Tests complete. c. Error: square(3)Tests complete. d. Tests complete.

B

67. Which is true? a. A program with multiple classes is contained in a single file b. A programmer must decide what a class contains and does c. Class data are normally public d. A programmer should sketch a class while writing the code

B

8. Which is a valid method call for findMax()? public static double findMax(double x, double y){. . .} a. double val = findMax(); b. double val = findMax(4.2, 20.7); c. double val = findMax(19.6); d. int val = findMax(7.9, 20.3);

B

11. Which is the best stub for a method that calculates an item's tax? a. public static double ComputeTax(double itemPrice) { double TAXRATE = 0.0675; return itemPrice * TAXRATE; } b. public static double ComputeTax(double itemPrice) { double tax; return tax; } c. public static double ComputeTax(double itemPrice) { System.out.println("FIXME: Calculate tax"); return 0.0; } d. public static double ComputeTax(double itemPrice) { double tax = 0.0; }

C

13. A programmer develops code by repeating short sessions of writing, compiling, and testing until the project is finished. This is an example of _____. a. Pair programming b. Modular development c. Incremental development d. Parallel programming

C

15. During execution of main(), how many user-defined methods are called? public static double calcTax(double cost) { return cost * 0.15; } public static double calcShippingCost(double weight) { double cost; if(weight < 10) { cost = 10.0; } else { cost = 15.5; } cost = cost + calcTax(cost); return cost; } public static void main(String args[]) { double cost1; double cost2; cost1 = calcShippingCost(7.5); cost2 = calcShippingCost(17.5); } a. 0 b. 2 c. 4 d. 8

C

18. Which is true about arrays and methods? a. Arrays cannot be passed to methods b. Passing an array to a method creates a copy of the array within the method c. An array is passed to a method as a reference d. A programmer must make a copy of an array before passing the array to a method

C

19. What is output? public static void changeRainfall(double [] dailyRain) { dailyRain[0] = 0.1; } public static void main(String args[]) { double [] rainValues = new double[2]; rainValues[0] = 2.9; rainValues[1] = 1.3; changeRainfall(rainValues); System.out.println(rainValues[0]); } a. 2.9 b. 1.3 c. 0.1 d. an array reference

C

22. calcSum() was copied and modified to create calcProduct(). Which line in calcProduct() contains an error? 1 public static int calcSum(int a, int b) { 2 int s; 3 s = a + b; 4 return s; 5 } 6 public static int calcProduct(int a, int b) { 7 int p; 8 p = a * b; 9 return s; 10 } a. Line 7 b. Line 8 c. Line 9 d. There are no errors

C

28. What is the scope of odometer defined on line 7? 1 public class SimpleCar { 2 private int odometer; 3 public void driveForward(int miles) { 4 odometer = odometer + miles; 5 } 6 public void changeOdometer(int miles) { 7 int odometer; 8 odometer = miles; 9 } 10} a. method driveForward() b. odometer is not defined c. method changeOdometer() d. all of class SimpleCar

C

33. What is the output for the call displayTime(15, 24, 65)? public static void displayTime(int hr, int min, int sec) { if(hr < 1 || hr > 12) { System.out.print("Error: hour "); hr = 1; } if(min < 1 || min > 59) { System.out.print("Error: minute "); min = 1; } if(sec < 1 || sec > 59) { System.out.print("Error: second "); sec = 1; } System.out.println(hr + ":" + min + ":" + sec); } a. 15:24:65 b. 1:24:1 c. Error: hour Error: second 1:24:1 d. Error: second 1 :24:1

C

34. What is output? char[] emotion = {'n','o','t',' ','s','a','d'}; System.out.print(emotion.length); a. 3 b. 6 c. 7 d. Error: index out of bounds

C

37. What is output? public static void replace(int [] allGrades, int examScore) { allGrades[1] = examScore; } public static void main(String args[]) { int[] myGrades = {72,84,75,92,65}; replace(myGrades, 100); System.out.print(myGrades[1]); } a. 72 b. 84 c. 100 d. error

C

41. What is output? public static void curveGrades(int curve, int[] grades) { curve = curve + 5; grades[0] = grades[0] + curve; } public static void main(String[] args) { int[] myGrades = {72, 67, 85}; int amt; amt = 10; curveGrades(amt, myGrades); System.out.println(amt + ", " + myGrades[0]); } a. 10, 72 b. 15, 87 c. 10, 87 d. 10, 82

C

64. Features of a good testbench include: a. Messages for all tests that pass b. At least 90% code coverage c. Border cases and extreme values d. Test cases for all possible values

C

16. What is the output? public static double checkForFever (double temp) { final double NORMAL_TEMP = 98.6; final double CUTOFF_TEMP = 95; double degreesOfFever; if (temp > NORMAL_TEMP) { degreesOfFever = temp - NORMAL_TEMP; System.out.print("You have " + degreesOfFever + " degrees of fever."); } else if (temp < CUTOFF_TEMP) { degreesOfFever = CUTOFF_TEMP - temp; System.out.print("Your temperature is " + degreesOfFever + " below 95."; } return degreesOfFever; } public static void main(String args[]) { double bodyTemperature; double degreesOfFever; bodyTemperature = 96.0; System.out.print("Checking for fever..."); degreesOfFever = checkForFever(bodyTemperature); } a. Nothing is output b. Checking for fever...Your temperature is 2.6 below 95. c. Checking for fever...Your temperature is 2.6 below 95. d. Checking for fever...

D

17. What is output? public static void changeRainfall(double [] dailyRain) { dailyRain[0] = 0.1; } public static void main(String args[]) { double [] rainValues = new double[2]; rainValues[0] = 2.9; rainValues[1] = 1.3; changeRainfall(rainValues); System.out.println(rainValues); } a. 2.9 b. 1.3 c. 0.1 d. an array reference

D

20. Which is true regarding tripleTheValue()? public static int tripleTheValue(int val) { int tripleValue; tripleValue = val * 3; } a. val should be returned b. tripleValue should be defined as double c. there are no errors d. tripleValue should be returned

D

27. What is the scope of odometer defined on line 2 1 public class SimpleCar { 2 private int odometer; 3 public void driveForward(int miles) { 4 odometer = odometer + miles; 5 } 6 public void changeOdometer(int miles) { 7 int odometer; 8 odometer = miles; 9 } 10} a. method driveForward() b. odometer is not defined c. method changeOdometer() d. all of class SimpleCar

D

32. What is the output for the call displayTime(2, 24, 65)? public static void displayTime(int hr, int min, int sec) { if(hr < 1 || hr > 12) { System.out.print("Error: hour "); hr = 1; } if(min < 1 || min > 59) { System.out.print("Error: minute "); min = 1; } if(sec < 1 || sec > 59) { System.out.print("Error: second "); sec = 1; } System.out.println(hr + ":" + min + ":" + sec); } a. 2:24:65 b. 2:24:1 c. Error: second 2:24:65 d. Error: second 2:24:1

D

4. Given: public static void printName(String first, String last) { System.out.println(last + ", " + first); } What is printed with the following method call? printName("Bob", "Henderson"); a. Bob, Henderson b. Henderson,Bob c. Bob Henderson d. Henderson, Bob

D

44. Which statement is true? void swap(int age, int [] grades) { a. the value of age is stored in the heap b. the reference to grades is stored in the heap c. the elements in grades can not be modified within the method d. the value of grades[2] is stored in the heap

D

45. What is copiedNums' length after the code segment? int[] originalNums = {1,2,3,4,5}; int[] copiedNums; copiedNums = copy(originalNums, 2); public static int[] copy(int[] nums, int changeAmt) { int[] modifiedNums = new int[nums.length * changeAmt]; int index; for(index = 0; index < nums.length; ++index) { modifiedNums[index] = nums[index]; } return modifiedNums; } a. 0 b. 5 c. 7 d. 10

D

46. What us copiedNums' length after the code segment? int[] originalNums = {1, 2, 3, 4 }; public static int[] copy(int[] nums, int changeAmt) { int[] modifiedNums = new int[nums.length * changeAmt]; int index; for(index = 0; index < nums.length; ++index) { modifiedNums[index] = nums[index]; } return modifiedNums; } a. 3 b. 4 c. 6 d. 8

D

50. Which XXX in firstHalf() that returns a new array with a copy of the first half of all elements in array nums. public static int[] firstHalf(int[] nums) { int index; int size = nums.length / 2; XXX for(index = 0; index < size; ++index) { halfNums[index] = nums[index]; } return halfNums; } a. int[] halfNums; b. int halfNums = new int[size]; c. int[] halfNums = new int[nums.length]; d. int[] halfNums = new int[size];

D

57. Mustang is an object of type Car. Which statement invokes drive()? a. Car.drive(150); b. drive(135); c. mustang->drive(115); d. mustang.drive(145);

D

58. How many object references are declared? Car mustang = new Car();Car prius;int miles;Truck tundra = new Truck(); a. 0 b. 1 c. 2 d. 3

D

59. How many fields are declared in the Car class? public class Car { /** declare private fields ... *public void drive(int miles) {}; *public void addGas(double gallons) {}; **/public int checkOdometer() {}; } a. 0 b. 2 c. 3 d. Unknown

D

60. What is the value of fordFusion's odometer at the end of main( )? public class SimpleCar { private int odometer; public SimpleCar() { odometer = 0; } public SimpleCar(int miles) { odometer = miles; } public void drive(int miles) { odometer = odometer + miles; } public static void main(String[] args) { SimpleCar fordFusion = new SimpleCar(); SimpleCar hondaAccord = new SimpleCar(30); fordFusion.drive(100); fordFusion.drive(20); } } a. 20 b. 30 c. 100 d. 120

D

61. If myClass has a constructor with a parameter of type String, select the other constructor that should be included. a. public void myClass( ) {. . .} b. public myClass(int value ) {. . .} c. public myClass(String str1, String str2) {. . .} d. public myClass( ) {. . .}

D

9. The following program generates an error. Why? public static void printSum(int num1, int num2) { System.out.print(num1 + num2); } public static void main(String args[]) { int y; y = printSum(4, 5); return 0; } a. printSum() is missing a "return;" statement. b. The values 4 and 5 cannot be passed directly to printSum() c. main() has a return statement that returns the value 0 d. printSum() has void return type, so cannot be assigned to a variable

D


Set pelajaran terkait

OB Chapter 13 Labor and Delivery

View Set

DLC210: Implementing the Army's Physical Readiness Training (PRT) Program

View Set

Genetics - Ch. 9 DNA Replication & Recombination

View Set

Practice - questions test bank - Chapter 6, Values, Ethics, and Advocacy

View Set

Personal Financial Planning Final Exam

View Set

How can an organization provide superior customer value to customers? Group of answer choices

View Set

VNSG 5 Pharmacology 🙏❤️🙏

View Set