CSCI-185 Programming II - Assessment Test
CSCI-185 Programming II - Assessment Test
a) -1
b) 0
c) 1
d) 2
e) you can declare an array to have any indexes you choose
a) The integer value 2 will be assigned to the last index in the array.
b) The integer value 25 will be assigned to the second index in the array.
c) The integer value 25 will be assigned to the third value in the array.
d) This code will result in a compile-time error.
e) This code will result in a run-time error.
a) 26
b) 24
c) 25
d) This code will result in a compile time error.
e) This code will result in a run time error.
1
6) All methods (with the exception of constructors) must specify a return type. What is the return type for a method
that does not return any values?
a) int
b) void
c) public
d) double
e) none of the above
7) If a service is so complex that it cannot be reasonably be implemented using one method, it is often helpful to
decompose it to make use of ________________ support methods.
a) static
b) aggregate
c) private
d) public
e) final
8) A special method that is invoked to set up an object during instantiation is called a ___________________.
a) new method
b) dot operator
c) creator
d) destructor
e) constructor
a) !
b) &&
c) ||
d) <
e) >
10) What happens if a case in a switch statement does not end with a break statement?
11) Suppose we want to condition an if statement on whether two String objects, referenced by stringOne and
stringTwo, are the same. Which of the following is the correct way to achieve this?
a) if(stringOne == stringTwo)
b) if(stringOne.compareTo(stringTwo))
c) if(stringOne.equals(stringTwo))
d) if(stringOne != stringTwo)
e) if(stringOne === stringTwo)
2
12) In order to make a variable a constant which modifier must be included in its declaration?
a) public
b) static
c) void
d) private
e) final
result = 15 % 4;
a) 0
b) 1
c) 2
d) 3
e) 4
14) Which of the following lines allows a programmer to use the Scanner class in a Java program?
a) import java.util.Scanner;
b) using Scanner;
c) include Scanner;
d) include java.util.Scanner;
e) any of the above will allow the programmer to use the Scanner class
a) 30 plus 25 is 55
b) 30 plus 25 is 30
c) 30 plus 25 is 25
d) 30 plus 25 is 3025
e) this snippet of code will result in a compiler error
a) attributes
b) white spaces
c) methods
d) variables
e) name
17) The Java compiler translates Java source code into _____________ .
a) Java bytecode
b) C++
c) assembly code
d) machine code
e) an object-oriented language
3
18) A _____________ diagram helps us visualize the contents of and relationships among the classes of a program.
19) Which of the following object-oriented principles refers to the fact that an object should have its data guarded
from inappropriate access?
a) encapsulation
b) inheritance
c) polymorphism
d) instance variables
e) methods
20) When applied to instance variables, the ________________ visibility modifier enforces encapsulation.
a) static
b) final
c) public
d) private
e) none of the above
21) Which of the following method headers is most likely a header for a mutator method?
23) Suppose we have an array of String objects identified by the variable names. Which of the following for
loops will not correctly process each element in the array.
24) Which of the following statements will assign the first command-line argument sent into a Java program to a
variable called argument?
a) argument = System.getFirstArgument();
b) argument = System.getArgument[1];
c) argument = System.getArgument[0];
d) argument = args[0];
e) argument = args[1];
4
25) Which of the following is a valid declaration for a two-dimensional array?
a) int[][] matrix;
b) int[2] matrix;
c) int[]** matrix;
d) int[] matrix;
e) none of these are correct
26) Which of the following lines of code accesses the second element of the first array in a two-dimensional array
of integers, numbers, and stores the result in a variable called num?
a) num = numbers[1][2];
b) num = numbers[0][1];
c) num = numbers.getElement(1, 2);
d) num = numbers.getElement(0, 1);
e) none of the above are correct
27) Every Java array is a(n) _________________, so it is possible to use a foreach loop to process each element in
the array.
a) object
b) class
c) operator
d) none of the above
e) iterator