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 BookSurge.com.
Are you a university student studying Java programming? Do you agree that my book would serve as a helpful workbook and companion to be used along with the Java fundamentals textbook that is currently being used in your class? If so, then please ask your professor to consider using my book in future classes.
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.
I would also like to read your response to the following questions.
class GFC404 {
private static int x=1;
static void m1(int x, int y) {x++; y++;}
public static void main (String[] args) {
int y=3; m1(x, y);
System.out.println(x + "," + y);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 1,3 |
| b. | Prints: 2,3 |
| c. | Prints: 1,4 |
| d. | Prints: 2,4 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class EBH011 {
public static void main (String[] args) {
float a = Float.POSITIVE_INFINITY;
double b = Double.POSITIVE_INFINITY;
double c = Double.NaN;
System.out.print((a == b)+","+(c == c)+","+(c != c));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: false,true,true |
| e. | Prints: true,false,false |
| f. | Prints: true,false,true |
| g. | Prints: true,true,false |
| h. | Prints: true,true,true |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class A {
public static void main(String[] args) {
char a = 'a', b = 'b'; // 'a' = 97, 'b' = 98
System.out.print(a + b + "" + a + b);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 390 |
| b. | Prints: 195195 |
| c. | Prints: 195ab |
| d. | Prints: ab195 |
| e. | Prints: abab |
| f. | Run-time error |
| g. | Compile-time error |
| h. | None of the above |
class EBH012 {
public static void main (String[] args) {
byte x = 3, y = 5;
System.out.print((-x == ~x + 1)+","+(-y == ~y + 1));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false |
| b. | Prints: false,true |
| c. | Prints: true,false |
| d. | Prints: true,true |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class EBH007{
public static void main (String[] s) {
byte b = 5; System.out.println(b<<33);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: -1 |
| b. | Prints: 0 |
| c. | Prints: 1 |
| d. | Prints: 5 |
| e. | Prints: 10 |
| f. | Run-time error |
| g. | Compile-time error |
| h. | None of the above |
class Sienna {
static double a; static float b; static int c; static char d;
public static void main(String[] args) {
a = b = c = d = 'a';
System.out.println(a+b+c+d == 4 * 'a');
}}
What is the result of attempting to compile and run the program?
| a. | Prints: true |
| b. | Prints: false |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
interface I1 {} interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Silver {
public static void main(String []args) {
Base[] base = {new Base()};
Sub sub[] = new Sub[1]; // 1
Object obj = base; // 2
sub = (Sub[])obj; // 3
I1 []i1 = (I1[])obj; // 4
}}
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. | Compile-time error at line 4 |
| h. | Run-time error at line 4 |
| i. | 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 GFC200 {}
class GFC201 {
static void m(Object x) {System.out.print("Object");}
static void m(String x) {System.out.print("String");}
static void m(GFC200 x) {System.out.print("GFC200");}
public static void main(String[] args) {m(null);}
}
What is the result of attempting to compile and run the program?
| a. | Prints: Object |
| b. | Prints: String |
| c. | Prints: GFC200 |
| d. | Compile-time error |
| e. | Run-time error |
| f. | None of the above |
class UltraViolet {
public static void main (String[] args) {
char a = '\u002a', b = '\u0024'; // a = Asterisk *; b = Dollar Sign $
System.out.print(a + b); // 1
System.out.print(" ABC" + a + b); // 2
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 78 ABC*$ |
| b. | Prints: *$ ABC*$ |
| c. | Prints: 78 ABC78 |
| d. | Compile-time error |
| e. | Run-time error |
| f. | None of the above |
class GFC202 {} class GFC203 extends GFC202 {}
class GFC204 {
static void m(GFC202 x) {System.out.print("GFC202");}
static void m(GFC203 x) {System.out.print("GFC203");}
public static void main(String[] args) {m(null);}
}
What is the result of attempting to compile and run the program?
| a. | Prints: GFC202 |
| b. | Prints: GFC203 |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
class GFC305 {
static void m1(int[] i1, int[] i2) {
int i = i1[0]; i1[0] = i2[0]; i2[0] = i;
}
public static void main (String[] args) {
int[] i1 = {1}, i2 = {3}; m1(i1, i2);
System.out.print(i1[0] + "," + i2[0]);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 1,1 |
| b. | Prints: 1,3 |
| c. | Prints: 3,1 |
| d. | Prints: 3,3 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class EBH105 {
static int m(int i) {System.out.print(i + ","); return 0;}
public static void main (String[] args) {
int i = 0; i = i++ + m(i); System.out.print(i);
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 0,0 |
| b. | Prints: 1,0 |
| c. | Prints: 0,1 |
| d. | Prints: 1,1 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class GFC306 {
static int[] i1 = {1}, i2 = {3};
static void m1(int[] i1) {
int[] i3 = i1; i1 = i2; i2 = i3;
}
public static void main (String[] args) {
m1(i1);
System.out.print(i1[0] + "," + i2[0]);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 1,1 |
| b. | Prints: 1,3 |
| c. | Prints: 3,1 |
| d. | Prints: 3,3 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class EBH106 {
public static void main(String args[]) {
int a = 1; a += ++a + a++; System.out.print(a);
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 3 |
| b. | Prints: 4 |
| c. | Prints: 5 |
| d. | Prints: 6 |
| e. | Prints: 7 |
| f. | Run-time error |
| g. | Compile-time error |
| h. | 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 |
class GFC307 {
static void m1(int[] i1, int[] i2) {
i1 = i2 = null;
}
public static void main (String[] args) {
int[] i1 = {1}, i2 = {3}; m1(i1, i2);
System.out.print(i1[0] + "," + i2[0]);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,0 |
| b. | Prints: 1,1 |
| c. | Prints: 1,3 |
| d. | Prints: 3,1 |
| e. | Prints: null,null |
| f. | Run-time error |
| g. | Compile-time error |
| h. | None of the above |
class EBH107 {
static int m(int i) {System.out.print(i + ","); return i;}
public static void main(String s[]) {
int i=0, j = m(++i) + m(++i) * m(++i) % m(++i) + m(++i);
System.out.print(j%5);
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1,2,3,4,5,0 |
| b. | Prints: 1,2,3,4,5,1 |
| c. | Prints: 1,2,3,4,5,2 |
| d. | Prints: 1,2,3,4,5,3 |
| e. | Prints: 1,2,3,4,5,4 |
| f. | Prints: 1,2,3,4,5,5 |
| g. | Run-time error |
| h. | Compile-time error |
| i. | None of the above |