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 Green {
public static void main (String args[]) {
int[] i = null; // 1
Cloneable c = i; // 2
i = (int [])c; // 3
}}
What is the result of attempting to compile and run the program?
| a. | Compile-time error at line 1. |
| b. | Run-time error at line 1. |
| c. | Compile-time error at line 2. |
| d. | Run-time error at line 2. |
| e. | Compile-time error at line 3. |
| f. | Run-time error at line 3. |
| g. | None of the above |
class Purple {
public static void main (String []args) {
int[] i = {1,2,3}; // 1
Object obj = i; // 2
i = obj; // 3
}}
What is the result of attempting to compile and run the program?
| a. | Compile-time error at line 1. |
| b. | Run-time error at line 1. |
| c. | Compile-time error at line 2. |
| d. | Run-time error at line 2. |
| e. | Compile-time error at line 3. |
| f. | Run-time error at line 3. |
| g. | None of the above |
import java.io.Serializable;
class Blue {
public static void main (String args[]) {
int[] i = {1,2,3}; // 1
Serializable s = i; // 2
i = (int [])s; // 3
}}
What is the result of attempting to compile and run the program?
| a. | Compile-time error at line 1. |
| b. | Run-time error at line 1. |
| c. | Compile-time error at line 2. |
| d. | Run-time error at line 2. |
| e. | Compile-time error at line 3. |
| f. | Run-time error at line 3. |
| g. | None of the above |
class Black {
public static void main(String args[]) {
int[] i = {1,2,3,4,5}; // 1
long[] l = new long[5]; // 2
for (int j = 0; j < l.length(); j++) { // 3
l[j] = i[j]; // 4
}}}
A compile-time error is generated at which line?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | None of the above |
class White {
public static void main(String args[]) {
int[] i = {1,2,3,4,5}; // 1
long[] l1 = new long[5]; // 2
long []l2 = l1; // 3
long l3[] = (long[])i; // 4
long l4[] = new long[5]; // 5
l4[1] = i[1]; // 6
}}
A compile-time error is generated at which line?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
| f. | 6 |
| g. | None of the above |
class Amber {
public static void main(String[] args) {
int[][] a = {{1,2},{0,1,2},{-1,0,2}}; // 1
Object[] obj = (Object[])a.clone(); // 2
for(int i = 0; i < obj.length; i++) { // 3
int[] ia = (int[])obj[i]; // 4
System.out.print(ia[i]); // 5
}}}
A compile-time error is generated at which line?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
| f. | None of the above |