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.
public class Basics {} // 1
class Basics1 {} // 2
protected class Basics2 {} // 3
private class Basics3 {} // 4
Class Basics4 {} // 5
Suppose these are top-level class declarations and not nested class declarations; and suppose that all of the declarations are contained in one file named Basics.java. Compile-time errors are generated at which lines?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
public class Basics {} // 1
public class Basics2 {} // 2
public class Basics3 {} // 3
public class Basics4 {} // 4
Suppose these are top-level class declarations and not nested class declarations; and suppose that all of the declarations are contained in one file named Basics.java. A compile-time error is not generated at which line?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | None of the above |
class JSC102 {
public static void main (String[] args) {
private int x = 1; protected int y = 2; public int z = 3;
System.out.println(x+y+z);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 123 |
| b. | Prints: 1 2 3 |
| c. | Prints: 6 |
| d. | Run-time error |
| e. | Compile-time error |
| f. | None of the above |
class JSC105 {
private static int x; protected static int y; public static int z;
public static void main (String[] args) {System.out.println(x+y+z);}
}
What is the result of attempting to compile and run the program?
| a. | Prints nothing. |
| b. | Prints an undefined value. |
| c. | Prints: null |
| d. | Prints: 0 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class Red {
public int a; public static int b;
public static void main (String[] in) {
Red r1 = new Red(), r2 = new Red(); r1.a++; r1.b++;
System.out.print(r1.a+", "+r1.b+", "+r2.a+", "+r2.b);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0, 0, 0, 0 |
| b. | Prints: 0, 1, 1, 1 |
| c. | Prints: 1, 1, 1, 0 |
| d. | Prints: 1, 1, 0, 1 |
| e. | Prints: 1, 1, 0, 0 |
| f. | Prints: 1, 1, 1, 1 |
| g. | Compile-time error |
| h. | Run-time error |
| i. | None of the above |
class Basics {
int x = 1, y = 2;
public static void main (String[] args) {System.out.println(x+y);}
}
What is the result of attempting to compile and run the program?
| a. | Prints: x+y |
| b. | Prints: 12 |
| c. | Prints: 3 |
| d. | Run-time error |
| e. | Compile-time error |
| f. | None of the above |
Suppose that the compiler generates a default constructor for a class. If a compile-time error is to be avoided, which of the following must be true?
| a. | The superclass must not have any constructor other than a default constructor. |
| b. | The superclass must not have an accessible no-argument constructor. |
| c. | The no-argument superclass constructor must not have a throws clause that includes a checked exception. |
| d. | The no-argument superclass constructor must be declared private. |
| e. | None of the above |
Which of the following statements are true?
| a. | A value can not be assigned to a final field more than once. |
| b. | A value can be assigned to a final field at any time or not at all. |
| c. | Only static variables can be declared final. |
| d. | A compile-time error is thrown if a blank final instance variable is not assigned a value before the end of each constructor. |
| e. | A field can not be declared both final and volatile. |
Which of the following statements is true?
| a. | An abstract method can not be overridden by an abstract method. |
| b. | An instance method that is not abstract can not be overridden by an abstract method. |
| c. | An abstract method declaration can not include a throws clause. |
| d. | The body of an abstract method is represented by a set of empty brackets. |
| e. | None of the above. |
class JSC204 {
static int m1(short s) {return s;} // 1
static int m2(float f) {return f;} // 2
public static void main(String[] args) {
short s = 3; float f = 5.0f;
System.out.print(""+m1(s)+m2(f));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 35.0 |
| b. | Prints: 8.0 |
| c. | Compile-time error at 1. |
| d. | Compile-time error at 2. |
| e. | Run-time error |
| f. | None of the above |
class A {A() throws Exception {}} // 1
class B extends A {B() throws Exception {}} // 2
class C extends A {} // 3
Which of the following statements is true?
| a. | Compile-time error at 1. |
| b. | Compile-time error at 2. |
| c. | Compile-time error at 3. |
| d. | None of the above |
class JSC101 {
void m1() {
public int a; // 1
protected int b; // 2
private int c; // 3
static int d; // 4
transient int e; // 5
volatile int f; // 6
final int g = 1; // 7
}}
Compile-time errors are generated at which lines?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
| f. | 6 |
| g. | 7 |
Which of the following statements is not true?
| a. | A static method is also known as a class method. |
| b. | A class method is not associated with a particular instance of the class. |
| c. | The keyword, this, can not be used inside the body of a static method. |
| d. | The keyword, super, may be used in the body of a static method. |
| e. | A method that is not static is known as an instance method. |
| f. | None of the above. |
class JSC205 {
static int m1(int i) {return i;} // 1
static void m2(int i) {return i;} // 2
static int m3(int i) {return;} // 3
public static void main(String[] args) {
System.out.print(""+m1(1)+m2(2)+m3(3)); // 4
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 123 |
| b. | Prints: 6 |
| c. | Compile-time error at 1. |
| d. | Compile-time error at 2. |
| e. | Compile-time error at 3. |
| f. | Compile-time error at 4. |
Which of the following statements are true?
| a. | A final method can not be overridden. |
| b. | All methods declared in a final class are implicitly final. |
| c. | The methods declared in a final class must be explicitly declared final or a compile-time error occurs. |
| d. | It is a compile-time error if a private method is declared final. |
| e. | A machine-code generator can inline the body of a final method. |
abstract class A {} // 1
transient class G {} // 2
private class C {} // 3
static class E {} // 4
Suppose these are top-level class declarations and not nested class declarations. Which of these declarations would not produce a compile-time error?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | None of the above |
class JSC103 {
transient float e = 1; // 1
volatile float f = 1; // 2
abstract float j = 1; // 3
final float g = 1; // 4
private final float k = 1; // 5
private transient float l = 1; // 6
volatile final float m = 1; // 7
}
Compile-time errors are generated at which lines?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
| f. | 6 |
| g. | 7 |
Which of the following statements are true?
| a. | If an accessible superclass method is static, then any method with the same signature in a subclass must also be static. |
| b. | If a superclass method is synchronized, then the overriding method must also be synchronized. |
| c. | If a superclass method is public, then the overriding method must also be public. |
| d. | If a superclass method is native, then the overriding method must also be native. |
| e. | If a superclass method is protected, then the overriding method must be protected or public. |
protected class D {} // 1
synchronized class F {} // 2
volatile class H {} // 3
final class B {} // 4
Suppose these are top-level class declarations and not nested class declarations. Which of these declarations would not produce a compile-time error?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | None of the above |
class JSC104{
public float a; // 1
protected float b; // 2
private float c; // 3
static float d; // 4
synchronized float 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. |