The pages of this web site are not formatted to conserve paper, but my new book (ISBN: 0-9745862-0-X) is formatted to save paper, save your printer cartridge, save a loose-leaf binder, and save money. If you prefer to work my exams from printed pages, then give your printer a rest and buy my new book.
Today, you can find my book at amazon.com.
If you have any questions or comments concerning my mock exams or my book, then please send an e-mail to me at scjpexam2000@yahoo.com.
class MWC201 {
public static void main(String[] args) {
int[][] a1 = {{1,2,3},{4,5,6},{7,8,9,10}};
System.out.print(a1[0][2]+","+a1[1][0]+","+a1[2][1]);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 3,4,8 |
| b. | Prints: 7,2,6 |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
class MWC202 {
public static void main(String[] args) {
int[] a1[] = {{1,2},{3,4,5},{6,7,8,9}};
int []a2[] = {{1,2},{3,4,5},{6,7,8,9}};
int a3[][] = {{1,2},{3,4,5},{6,7,8,9}};
System.out.print(a1[0][1]+","+a2[1][2]+","+a3[2][3]);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 14 |
| b. | Prints: 16 |
| c. | Prints: 1,5,9 |
| d. | Prints: 2,4,8 |
| e. | Prints: 2,5,9 |
| f. | Compile-time error |
| g. | Run-time error |
| h. | None of the above |
class MWC207 {
public static void main(String[] args) {
int[][] a1 = {{1;2};{3;4;5};{6;7;8;9}};
System.out.print(a1[0][1]+","+a1[1][2]+","+a1[2][3]);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 14 |
| b. | Prints: 16 |
| c. | Prints: 1,5,9 |
| d. | Prints: 2,4,8 |
| e. | Prints: 2,5,9 |
| f. | Compile-time error |
| g. | Run-time error |
| h. | None of the above |
class MWC208 {
public static void main(String[] args) {
int[][] a1 = ((1,2),(3,4,5),(6,7,8,9));
System.out.print(a1[0][1]+","+a1[1][2]+","+a1[2][3]);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 14 |
| b. | Prints: 16 |
| c. | Prints: 1,5,9 |
| d. | Prints: 2,4,8 |
| e. | Prints: 2,5,9 |
| f. | Compile-time error |
| g. | Run-time error |
| h. | None of the above |
class MWC209 {
public static void main(String[] args) {
int[][] a1 = [[1,2],[3,4,5],[6,7,8,9]];
int[][] a2 = [[1,2],[3,4,5],[6,7,8,9]];
int[][] a3 = [[1,2],[3,4,5],[6,7,8,9]];
System.out.print(a1[0][1]+","+a2[1][2]+","+a3[2][3]);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 14 |
| b. | Prints: 16 |
| c. | Prints: 1,5,9 |
| d. | Prints: 2,4,8 |
| e. | Prints: 2,5,9 |
| f. | Compile-time error |
| g. | Run-time error |
| h. | None of the above |
class MWC210 {
public static void main(String[] args) {
int[] a2 = {1,2}, a3 = {3,4,5}, a4 = {6,7,8,9}; // 1
int[][] a1 = {a2,a3,a4}; // 2
System.out.print(a1[0][1]+","+a1[1][2]+","+a1[2][3]);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 14 |
| b. | Prints: 16 |
| c. | Prints: 1,5,9 |
| d. | Prints: 2,4,8 |
| e. | Prints: 2,5,9 |
| f. | Compile-time error |
| g. | Run-time error |
| h. | None of the above |
class MWC211 {
public static void main(String[] args) {
int a1[3]; // 1
int []a2[]; // 2
int[ ]a3; // 3
int[] a4[]; // 4
}}
A compile-time error is generated at which line?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | None of the above |
class MWC212 {
public static void main(String[] args) {
int[] a1[],a2[]; // 1
int []a3,[]a4; // 2
int []a5,a6[]; // 3
int[] a7,a8[]; // 4
}}
A compile-time error is generated at which line?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | None of the above |
class MWC203 {
public static void main(String[] args) {
int[] a1[] = {new int[]{1,2},new int[]{3,4,5}};
int []a2[] = new int[][]{{1,2},{3,4,5}};
int a3[][] = {{1,2},new int[]{3,4,5}};
System.out.print(a1[0][1]+","+a2[1][0]+","+a3[1][2]);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 14 |
| b. | Prints: 16 |
| c. | Prints: 1,2,4 |
| d. | Prints: 2,3,4 |
| e. | Prints: 2,3,5 |
| f. | Prints: 2,4,5 |
| g. | Compile-time error |
| h. | Run-time error |
| i. | None of the above |
class MWC204 {
public static void main(String[] args) {
int[][] a1 = {{1,2},{3,4,5},{6,7,8,9},{}};
System.out.print(a1.length);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0 |
| b. | Prints: 3 |
| c. | Prints: 4 |
| d. | Prints: 9 |
| e. | Prints: 10 |
| f. | Prints: 11 |
| g. | Compile-time error |
| h. | Run-time error |
| i. | None of the above |
class MWC205 {
public static void main(String[] args) {
int[][] a1 = {{1,2},{3,4,5},{6,7,8,9},{}};
for (int i = 0; i < a1.length; i++) {
System.out.print(a1[i].length+",");
}}}
What is the result of attempting to compile and run the program?
| a. | Prints: 2,3,4,0, |
| b. | Prints: 1,2,5,0, |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
class MWC206 {
public static void main (String[] args) {
int[][] a1 = {{1,2,3},{4,5,6},{7,8,9}};
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(a1[j][i]);
}}}}
What is the result of attempting to compile and run the program?
| a. | Prints: 123456789 |
| b. | Prints: 147258369 |
| c. | Prints: 321654987 |
| d. | Prints: 369258147 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class A11 {public String toString() {return "A11";}}
class A12 {
public static void main(String[] arg) {
A11[] a1 = new A11[1]; // 1
A11[][] a2 = new A11[2][]; // 2
A11[][][] a3 = new A11[3][][]; // 3
a1[0] = new A11(); // 4
a2[0] = a2[1] = a1; // 5
a3[0] = a3[1] = a3[2] = a2; // 6
System.out.print(a3[2][1][0]); // 7
}}
What is the result of attempting to compile and run the program?
| a. | Prints: null |
| b. | Prints: A11 |
| c. | Compile-time error at 1. |
| d. | Compile-time error at 2. |
| e. | Compile-time error at 3. |
| f. | Compile-time error at 4. |
| g. | Compile-time error at 5. |
| h. | Compile-time error at 6. |
| i. | Compile-time error at 7. |
| j. | Run-time error |
| k. | None of the above |
class A13 {}
class A14 {
public static void main(String[] arg) {
A13[] a1 = new A13[1]; // 1
A13[][] a2 = new A13[2][1]; // 2
A13[][][] a3 = new A13[3][3][3]; // 3
System.out.print(a3[2][2][2]); // 4
a1[0] = new A13(); // 5
a2[0] = a2[1] = a1; // 6
a3[0] = a3[1] = a3[2] = a2; // 7
System.out.print(a3[2][2][2]); // 8
}}
What is the result of attempting to compile and run the program?
| a. | Prints: null |
| b. | Prints: nullnull |
| c. | Compile-time error at 1. |
| d. | Compile-time error at 2. |
| e. | Compile-time error at 3. |
| f. | Compile-time error at 4. |
| g. | Compile-time error at 5. |
| h. | Compile-time error at 6. |
| i. | Compile-time error at 7. |
| j. | Compile-time error at 8. |
| k. | Run-time error |