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.
interface A {
void m1(); // 1
public void m2(); // 2
protected void m3(); // 3
private void m4(); // 4
}
Compile-time errors are generated at which lines?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
Which of the following statements is not true?
| a. | An interface that is declared within the body of a class or interface is known as a nested interface. |
| b. | A constant can be a member of an interface. |
| c. | A class declaration can be a member of an interface. |
| d. | If an interface is named in the implements clause of a class, then the class must implement all of the methods declared within the interface. |
| e. | None of the above. |
Which of the following statements are true?
| a. | An interface declaration can be a member of an interface. |
| b. | A method declared within an interface must have a body represented by empty curly braces. |
| c. | An interface can implement another interface. |
| d. | An abstract class that implements an interface must implement all abstract methods declared within the interface. |
| e. | An abstract method declaration can be a member of an interface. |
Which of the following are modifiers that can be applied to an interface that is a member of a directly enclosing interface?
| a. | abstract |
| b. | implements |
| c. | final |
| d. | private |
| e. | protected |
| f. | public |
Which of the following are modifiers that can be applied to an interface that is a member of a directly enclosing class?
| a. | abstract |
| b. | extends |
| c. | final |
| d. | private |
| e. | protected |
| f. | public |
Which of the following is a modifier that can be applied to an interface that is a member of a directly enclosing class or interface?
| a. | static |
| b. | synchronized |
| c. | transient |
| d. | volatile |
| e. | implements |
| f. | None of the above. |
Suppose that an interface, I1, is not a member of an enclosing class or interface. Which of the following modifiers can be applied to interface I1?
| a. | abstract |
| b. | final |
| c. | private |
| d. | protected |
| e. | public |
Suppose that an interface, I1, is not a member of an enclosing class or interface. Which of the following modifiers can be applied to interface I1?
| a. | abstract |
| b. | public |
| c. | static |
| d. | synchronized |
| e. | transient |
| f. | volatile |
Which of the following are modifiers that can be applied to a field declaration within an interface?
| a. | abstract |
| b. | const |
| c. | final |
| d. | private |
| e. | protected |
| f. | public |
Which of the following is a modifier that can be applied to a field declaration within an interface?
| a. | static |
| b. | synchronized |
| c. | transient |
| d. | volatile |
| e. | None of the above. |
Which of the following modifiers can be applied to a class that is declared within an enclosing interface?
| a. | public |
| b. | protected |
| c. | private |
| d. | abstract |
| e. | static |
| f. | final |
interface A {
int a = 1; // 1
public int b = 2; // 2
public static int c = 3; // 3
public static final int d = 4; // 4
}
Which field declaration results in a compile-time error?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | None of the above |
interface A {
protected int e = 5; // 1
private int f = 6; // 2
volatile int g = 7; // 3
transient int h = 8; // 4
public static final int d = 9; // 5
}
Which of the field declarations does not result in a compile-time error?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
| f. | None of the above |
Which of the following are modifiers that can be applied to a method declaration within an interface?
| a. | abstract |
| b. | final |
| c. | private |
| d. | protected |
| e. | public |
Which of the following is a modifier that can be applied to a method declaration within an interface?
| a. | static |
| b. | synchronized |
| c. | transient |
| d. | volatile |
| e. | native |
| f. | None of the above |
interface A {void m1();} // 1
class B implements A {public void m1() {}} // 2
class C implements A {protected void m1() {}} // 3
class D implements A {private void m1() {}} // 4
class E implements A {void m1() {}} // 5
Compile-time errors are generated at which lines?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
interface A {
void m1(); // 1
public void m2(); // 2
protected void m3(); // 3
private void m4(); // 4
abstract void m5(); // 5
}
Compile-time errors are generated at which lines?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
interface A {
final void m1(); // 1
synchronized void m2(); // 2
native void m3(); // 3
abstract void m4(); // 4
public void m5(); // 5
}
Compile-time errors are generated at which lines?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
interface A {void main(String[] args);} // 1
interface B {public void main(String[] args);} // 2
interface C {public static void main(String[] args);} // 3
interface D {protected void main(String[] args);} // 4
interface E {private void main(String[] args);} // 5
Which interface declarations generate a Compile-time error?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | 5 |
interface F {abstract void main(String[] args);} // 1
interface G {synchronized void main(String[] args);} // 2
interface H {final void main(String[] args);} // 3
interface I {native void main(String[] args);} // 4
Which interface declaration does not generate a compile-time error?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | None of the above |
interface A {String s1 = "A"; String m1();}
interface B implements A {String s1 = "B"; String m1();}
class C implements B {
public String m1() {return s1;}
public static void main(String[] args) {
A a = new C(); System.out.print(a.m1());
}}
What is the result of attempting to compile and run the program?
| a. | Prints: A |
| b. | Prints: B |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
interface A {int i = 1; int m1();}
interface B extends A {int i = 10; int m1();}
class C implements B {
public int m1() {return ++i;}
public static void main(String[] args) {
System.out.print(new C().m1());
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 2 |
| b. | Prints: 11 |
| c. | Compile-time error |
| d. | Run-time error |
| e. | None of the above |
interface Z {void m1();} // 1
class A implements Z {void m1() {}} // 2
class B implements Z {public void m1() {}} // 3
abstract class C implements Z {public abstract void m1();} // 4
A Compile-time error is generated at which line?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | None of the above |
interface Z {void m1();} // 1
class D implements Z {public final void m1() {}} // 2
class E implements Z {public synchronized void m1() {}} // 3
class G implements Z {public native void m1();} // 4
A Compile-time error is generated at which line?
| a. | 1 |
| b. | 2 |
| c. | 3 |
| d. | 4 |
| e. | None of the above |
interface I10 {String name = "I10"; String s10 = "I10.s10";}
interface I20 {String name = "I20"; String s20 = "I20.s20";}
class C10 implements I10, I20 { // 1
public static void main(String[] args) {
System.out.print(s10+","); // 2
System.out.print(s20+","); // 3
System.out.print(name); // 4
}}
What is the result of attempting to compile and run the program?
| a. | Prints: I10.s10,I20.s20,I10 |
| b. | Prints: I10.s10,I20.s20,I20 |
| c. | Prints: I10.s10,I20.s20, |
| d. | Prints: I10.s10,I20.s20,null |
| e. | Compile-time error at line 1 |
| f. | Compile-time error at line 2 |
| g. | Compile-time error at line 3 |
| h. | Compile-time error at line 4 |
| i. | Run-time error |
| j. | None of the above |
interface I10 {String name = "I10"; String s10 = "I10.s10";}
interface I20 {String name = "I20"; String s20 = "I20.s20";}
class C20 implements I10, I20 { // 1
public static void main(String[] args) {
System.out.print(I10.s10+","); // 2
System.out.print(I20.s20+","); // 3
System.out.print(I20.name); // 4
}}
What is the result of attempting to compile and run the program?
| a. | Prints: I10.s10,I20.s20,I10 |
| b. | Prints: I10.s10,I20.s20,I20 |
| c. | Prints: I10.s10,I20.s20, |
| d. | Prints: I10.s10,I20.s20,null |
| e. | Compile-time error at line 1 |
| f. | Compile-time error at line 2 |
| g. | Compile-time error at line 3 |
| h. | Compile-time error at line 4 |
| i. | Run-time error |
| j. | None of the above |