Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. ____ A do-while loop is guaranteed to run at least ______ time(s): a) zero b)

ID: 3574559 • Letter: 1

Question

1. ____ A do-while loop is guaranteed to run at least ______ time(s):
a) zero b) one c) infinite d) thirteen
2. _____ Consider the following code snippet:
public class Vehicle
{
private String type;
public String Vehicle(String type)
{
. . .
}
}
What is wrong with this code?
a) The class instance variable type must be initialized when it is declared.
b) The constructor must not have any arguments.
c) The constructor must not have a return type declared.
d) The constructor's return type must be void.
3. _____ The process of hiding object data and providing methods for data access is called ____.
a) documentation b) extension c) encapsulation d) initialization
4. _____ Which of the following statements about classes is correct?.
a) A class is an object that can be manipulated by a program.
b) A class describes a set of objects with the same behavior.
c) Class is another name for a method.
d) A class can contain only methods.
5. _____ Consider the following code snippet:
Coin coin1 = new Coin("dime", 0.10);
Coin coin2 = new Coin("dime", 0.10);
Which of the following statements is correct?
a) coin1 and coin2 contain references to the same object.
b) coin1 and coin2 refer to the same object.
c) coin1 and coin2 contain the same memory location.
d) coin1 and coin2 each have their own set of instance variables.
6. ____ Trying to access an element that is outside of the valid indices of an array generates what type of exception?
a) NumberFormatException b) IShouldHaveStudiedChapter7Exception
c) ArrayIndexOutOfBoundsException d) IllegalStateException
7. _____ Consider the statement: Apple[] cart = new Apple[512]; What type is cart[13] ?
a) integer b) Apple c) String d) unknown
8. _____ All of the following are methods of the ArrayList class except:
a) length() b) size() c) set() d) get()
9. _____ Which is the correct syntax for placing the string “boat” into an ArrayList named recVehicles in the 4th position
for the first time?
a) recVehicles.set(3, “boat”); b) recVehicles.set(“boat”, 3);
c) recVehicles.add(3, “boat”); d) recVehicles.add(“boat”, 3);
10. ____ What is the valid range of indices (index values) for an array of size 5?
a) 0 to 6 b) 1 to 5 c) 1 to 4 d) 0 to 4
11. ____ Which one of the following statements is the correct definition for a two-dimensional array of 2 rows and 20
columns of the type integer?
a) int[][] num = new int[20][2]; b) int[][] num = new int[2][20];
c) int[][] num = new int[20,2]; d) int[][] num = new int[2,20];

Explanation / Answer

1. C                                                                                                                                                     

2. C

3. C

4. B

5. A

6. C

7. C

8. C AND D

9. D

10. D

11. B