Batangas State University: The National Engineering University
Batangas State University: The National Engineering University
Integrated School
DATA CHECK 6
Long Test (Array and Function)
Computer Science 10
Object Oriented Programming
GENERAL DIRECTIONS:
1. Use permanent ink only in answering the tests. Erasures and alterations are not allowed.
2. Unanswered questions/items will be marked wrong.
3. Use the provided Answer Sheet.
I. Multiple Choice:
Directions: Choose letter the best answer in each of the following test items (1-40).
11. Which of the following is the correct syntax for declaring a single-dimensional array?
A. dataType arrayName;
B. dataType[arrayName];
C. arrayName[dataType];
D. dataType[] arrayName;
12. What is the maximum number of elements that can be stored in the following array: int[]
numArray = new int[7]?
A. 6
B. 7
C. 8
D. 9
Page 2 of 6
15. Which of the following is true about accessing elements in a one-dimensional array?
A. You can only access one element at a time.
B. You can access all elements in the array at once.
C. The first element in the array has an index of 1.
D. You can access elements in any order you want.
19. Which of the following is not a valid initialization of a two-dimensional array in Java?
A. int[][] num_array = {{1,2,3}, {4,5,6}};
B. int[][] num_array = {{1,2}, {3,4,5}};
C. int[][] num_array = {{1,2}, {3,4}, {5,6}, {7,8}};
D. int[][] num_array = {1,2,3,4,5};
20. What is the result of trying to access an element outside the bounds of a multidimensional
array in Java?
A. An ArrayIndexOutOfBoundsException is thrown
B. The element is set to null
C. The element is set to zero
D. The program terminates with an error message
Page 3 of 6
22. What is the data type of the variable "arr" in the given code block?
A. double
B. int
C. String
D. Boolean
24. What is the value of "row" if the given 2D array has no row with an even sum of elements?
A. -1
B. 0
C. numRows - 1
D. undefined
26. What happens if the user enters a non-numeric value when prompted for the size of the
array?
A. The program terminates with an error.
B. The program prompts the user to enter a numeric value.
C. The program initializes the array with a default size.
D. The program continues to execute normally, but the array may not be initialized
properly.
Page 4 of 6
27. How are the elements of the array printed to the console?
A. By using the System.out.println() method.
B. By using the Arrays.toString() method.
C. By iterating over the elements of the array with a for loop.
D. By passing the array to the System.out.print() method.
33. What is the difference between a void function and a function with a return value?
A. A void function does not return anything, while a function with a return value does.
B. A void function is used to store data, while a function with a return value is used for
calculations.
C. A void function is faster than a function with a return value.
D. A void function can be called from any location in a program, while a function with a
return value cannot.
34. What is the difference between predefined functions and user-defined functions in Java?
A. Predefined functions are defined by the user, while user-defined functions are built into
the Java language.
B. Predefined functions are used for specific tasks, while user-defined functions are used
to perform operations.
C. Predefined functions are stored in the Standard Function Library, while user-defined
functions are not.
D. Predefined functions are already defined in the Java language, while user-defined
functions are defined by the programmer.
Page 5 of 6
For numbers 36-40, refer to the codes below:
public static int compare(int a, int b, int c) {
if (a >= b && a >= c) {
return a;
} else if (b >= a && b >= c) {
return b;
} else {
return c;
}
}
36. What is the purpose of the compare method in the given code?
A. To compare the values of three numbers and return the greatest one.
B. To compare the values of three numbers and return the smallest one.
C. To calculate the average of three numbers and return the result.
D. To calculate the sum of three numbers and return the result.
37. What are the parameters of the compare method in this code?
A. a, b, c
B. scan
C. greatest
D. There are no parameters
39. What happens if two or three of the input numbers are equal in value?
A. The compare method returns one of the equal numbers.
B. The compare method returns zero.
C. The compare method returns -1.
D. The compare method returns an error.
Prepared:
Page 6 of 6