THE OCA EXAM TOPICS COVERED IN THIS PRACTICE TEST INCLUDE THE FOLLOWING:
What symbol is used for a varargs method parameter?
Fill in the blank in the following code to get the first element from the varargs parameter.
public void toss (Frisbee... f) {
Frisbee first = ____________;
}
Which of the following are primitives?
int[] lowercase = new int[0];
Integer[] uppercase = new Integer[0];
How many of the following are legal declarations?
[]double lion;
double[] tiger;
double bear[];
Given the following two methods, which method call will not compile?
public void printStormName(String... names) {
System.out.println(Arrays.toString(names));
}
public void printStormNames(String[] names) {
System.out.println(Arrays.toString(names));
}
How do you determine the number of elements in an array?
Which of the following create an empty two-dimensional array with dimensions 2×2?
How many lines does the following code output?
String[] days = new String[] { "Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday" };
for (int i = 0; i < days.length; i++)
System.out.println(days[i]);
What are the names of the methods to do searching and sorting respectively on arrays?
What does this code output?
String[] nums = new String[] { "1", "9", "10" };
Arrays.sort(nums);
System.out.println(Arrays.toString(nums));
Which of the following references the first and last element in a non-empty array?
How many of the following are legal declarations?
String lion [] = new String[] {"lion"};
String tiger [] = new String[1] {"tiger"};
String bear [] = new String[] {};
String ohMy [] = new String[0] {};
How many of the following are legal declarations?
float[] lion = new float[];
float[] tiger = new float[1];
float[] bear = new[] float;
float[] ohMy = new[1] float;
Which statement most accurately represents the relationship between searching and sorting with respect to the Arrays class?
Which is not a true statement about an array?
Which line of code causes an ArrayIndexOutOfBoundsException?
String[][] matrix = new String[1][2];
matrix[0][0] = "Don't think you are, know you are."; // m1
matrix[0][1] = "I'm trying to free your mind Neo"; // m2
matrix[1][0] = "Is all around you "; // m3
matrix[1][1] = "Why oh why didn't I take the BLUE pill?"; // m4
What does the following output?
String[] os = new String[] { "Mac", "Linux", "Windows" };
Arrays.sort(os);
System.out.println(Arrays.binarySearch(os, "Mac"));
Which is the first line to prevent this code from compiling and running without error?
char[][] ticTacToe = new char[3,3]; // r1
ticTacToe[1][3] = 'X'; // r2
ticTacToe[2][2] = 'X';
ticTacToe[3][1] = 'X';
System.out.println(ticTacToe.length + " in a row!"); // r3
How many objects are created when running the following code?
Integer[] lotto = new Integer[4];
lotto[0] = new Integer(1_000_000);
lotto[1] = new Integer(999_999);
How many of the following are legal declarations?
[][] String alpha;
[] String beta;
String[][] gamma;
String[] delta[];
String epsilon[][];
Which of the options in the graphic best represent the blocks variable?
char[][] blocks = new char[][] { { 'a', 'b', 'c' }, { 'd' }, { 'e', 'f' } };
What happens when calling the following method with a non-null and non-empty array?
public static void addStationName(String[] names) {
names[names.length] = "Times Square";
}
How many lines does the following code output?
String[] days = new String[] { "Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday" };
for (int i = 0; i < days.size(); i++)
System.out.println(days[i]);
How many dimensions does the array reference moreBools allow?
boolean[][][] bools, moreBools;
What is a possible output of the following code?
String[] strings = new String[2];
System.out.println(strings);
Which is the first line to prevent this code from compiling and running without error?
char[][] ticTacToe = new char[3][3]; // r1
ticTacToe[1][3] = 'X'; // r2
ticTacToe[2][2] = 'X';
ticTacToe[3][1] = 'X';
System.out.println(ticTacToe.length + " in a row!"); // r3
What is the result of running the following as java Copier?
package duplicate;
public class Copier {
public static void main(String... original) {
String... copy = original;
System.out.println(copy.length + " " + copy[0]);
}
}
What is the result of running the following program?
1: package fun;
2: public class Sudoku {
3: static int[][] game = new int[6][6];
4:
5: public static void main(String[] args) {
6: game[3][3] = 6;
7: Object[] obj = game;
8: obj[3] = "X";
9: System.out.println(game[3][3]);
10: }
11: }
What does the following output?
String[] os = new String[] { "Mac", "Linux", "Windows" };
Arrays.sort(os);
System.out.println(Arrays.binarySearch(os, "RedHat"));
What is the output of the following when run as java FirstName Wolfie?
public class FirstName {
public static void main(String... names) {
System.out.println(names[0]);
}
}
What is the output of the following when run as java Count 1 2?
public class Count {
public static void main(String target[]) {
System.out.println(target.length);
}
}
What is the output of the following when run as java unix.EchoFirst seed flower?
package unix;
import java.util.*;
public class EchoFirst {
public static void main(String[] args) {
String one = args[0];
Arrays.sort(args);
int result = Arrays.binarySearch(args, one);
System.out.println(result);
}
}
Which of these four array declarations produces a different array than the others?
How do you access the array element with the value of "z"?
How many lines does the following code output?
String[] days = new String[] { "Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday" };
for (int i = 1; i <= days.length; i++)
System.out.println(days[i]);
What is the output of the following when run as java FirstName Wolfie?
public class FirstName {
public static void main(String... names) {
System.out.println(names[1]);
}
}
Which is the first line to prevent this code from compiling and running without error?
char[][] ticTacToe = new char[3][3]; // r1
ticTacToe[0][0] = 'X'; // r2
ticTacToe[1][1] = 'X';
ticTacToe[2][2] = 'X';
System.out.println(ticTacToe.length + " in a row!"); // r3
What is the output of the following when run as java Count 1 2?
public class Count {
public static void main(String target[]) {
System.out.println(target.length());
}
}
How many dimensions does the array reference moreBools allow?
boolean[][] bools[], moreBools;
What is the result of the following when called as java counting.Binary?
package counting;
import java.util.*;
public class Binary {
public static void main(String... args) {
Arrays.sort(args);
System.out.println(Arrays.toString(args));
}
}
What does the following output?
String[] os = new String[] { "Mac", "Linux", "Windows" };
System.out.println(Arrays.binarySearch(os, "Linux"));
What is the result of running the following program?
1: package fun;
2: public class Sudoku {
3: static int[][] game;
4:
5: public static void main(String[] args) {
6: game[3][3] = 6;
7: Object[] obj = game;
8: game[3][3] = "X";
9: System.out.println(game[3][3]);
10: }
11: }
What is the output of the following?
String[][] listing = new String[][] { { "Book" }, { "Game", "29.99" } };
System.out.println(listing.length + " " + listing[0].length);
What is the output of the following when run as java FirstName?
public class FirstName {
public static void main(String[] names) {
System.out.println(names[0]);
}
}
How many lines does the following code output?
String[] days = new String[] { "Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday" };
for (int i = 1; i < days.length; i++)
System.out.println(days[i]);
What is the output of the following when run as java Count "1 2"?
public class Count {
public static void main(String target[]) {
System.out.println(target.length);
}
}
What does the following output?
String[] os = new String[] { "Linux", "Mac", "Windows" };
System.out.println(Arrays.binarySearch(os, "Linux"));
Which of the following statements are true?
Which of these four array references can point to an array that is different from the others?
What is the output of the following when run as java unix.EchoFirst seed flower?
package unix;
import java.util.*;
public class EchoFirst {
public static void main(String[] args) {
Arrays.sort(args);
String result = Arrays.binarySearch(args, args[0]);
System.out.println(result);
}
}