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 |
A class can not be called "tightly encapsulated" unless which of the following is true?
| a. | The class is a nested class. |
| b. | The constructors are declared private. |
| c. | The mutator methods are declared private. |
| d. | The class implements the Encapsulated interface. |
| e. | 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. | public |
| c. | static |
| d. | synchronized |
| e. | transient |
| f. | volatile |
A class can not be called "tightly encapsulated" unless which of the following is true?
| a. | All member fields are declared final. |
| b. | The class is not anonymous. |
| c. | The internal data model can be read and modified only through accessor and mutator methods. |
| d. | The class is an inner class. |
| e. | None of the above |
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 |
class GFC500 {private String name;}
class GFC501 {
private String name;
private void setName(String name) {this.name = name;}
private String getName() {return name;}
}
class GFC502 {
private String name;
public void setName(String name) {this.name = name;}
public String getName() {return name;}
}
Which class is not tightly encapsulated?
| a. | GFC501 |
| b. | GFC502 |
| c. | GFC503 |
| d. | None of the above |
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. |
class GFC505 extends GFC504 {
public void setName(String name) {this.name = name;}
public String getName() {return name;}
}
class GFC504 extends GFC503 {
private void setName(String name) {this.name = name;}
private String getName() {return name;}
}
class GFC503 {String name;}
Which class is tightly encapsulated?
| a. | GFC503 |
| b. | GFC504 |
| c. | GFC505 |
| d. | 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 |
class GFC506 {private String name;}
class GFC507 extends GFC506 {
String name;
public void setName(String name) {this.name = name;}
public String getName() {return name;}
}
class GFC508 extends GFC506 {
private String name;
public GFC508(String name) {setName(name);}
public void setName(String name) {this.name = name;}
public String getName() {return name;}
}
Which class is not tightly encapsulated?
| a. | GFC506 |
| b. | GFC507 |
| c. | GFC508 |
| d. | None of the above |
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 |
class A {void m1(String s1) {}}
class B extends A {
void m1(String s1) {} // 1
void m1(boolean b) {} // 2
void m1(byte b) throws Exception {} // 3
String m1(short s) {return new String();} //4
private void m1(char c) {} // 5
protected void m1(int i) {} // 6
}
What is the result of attempting to compile the program?
| a. | Compile-time error at line 1 |
| b. | Compile-time error at line 2 |
| c. | Compile-time error at line 3 |
| d. | Compile-time error at line 4 |
| e. | Compile-time error at line 5 |
| f. | Compile-time error at line 6 |
| g. | 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 |
class A {
void m1() {System.out.print("A.m1");}
}
class B extends A {
void m1() {System.out.print("B.m1");}
static void m1(String s) {System.out.print(s+",");}
}
class C {
public static void main (String[] args) {
B.m1("main"); new B().m1();
}}
What is the result of attempting to compile and run the program?
| a. | Prints: main,B.m1 |
| b. | Compile-time error |
| c. | Run-time error |
| d. | None of the above |
class T {
private int i1, i2;
void printI1I2() {System.out.print("T, i1="+i1+", i2="+i2);}
T(int i1, int i2) {
this.i1=i1; this.i2=i2;
}}
class U extends T {
private int i1, i2;
void printI1I2() {System.out.print("U, i1="+i1+", i2="+i2);}
U(int i1, int i2) {this.i1=i1; this.i2=i2;}
public static void main(String[] args) {
T t = new U(1,2); t.printI1I2();
}}
What is the result of attempting to compile and run the program?
| a. | Prints: U, i1=1, i2=2 |
| b. | Prints: T, i1=1, i2=2 |
| c. | Prints: U, i1=null, i2=null |
| d. | Prints: T, i1=null, i2=null |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class A {void m1(A a) {System.out.print("A");}}
class B extends A {void m1(B b) {System.out.print("B");}}
class C extends B {void m1(C c) {System.out.print("C");}}
class D {
public static void main(String[] args) {
A a1 = new A(); B b1 = new B();
C c1 = new C(); A c2 = new C();
c2.m1(a1); c2.m1(b1); c2.m1(c1);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: AAA |
| b. | Prints: ABC |
| c. | Prints: CCC |
| d. | Compile-time error |
| e. | Run-time error |
| f. | None of the above |
interface I {String s1 = "I";}
class A implements I {String s1 = "A";}
class B extends A {String s1 = "B";}
class C extends B {
String s1 = "C";
void printIt() {
System.out.print(((A)this).s1 + ((B)this).s1 +
((C)this).s1 + ((I)this).s1);
}
public static void main (String[] args) {
new C().printIt();
}}
What is the result of attempting to compile and run the program?
| a. | Prints: ABCI |
| b. | Run-time error |
| c. | Compile-time error |
| d. | None of the above |
class A {void m1(A a) {System.out.print("A");}}
class B extends A {void m1(B b) {System.out.print("B");}}
class C extends B {void m1(C c) {System.out.print("C");}}
class D {
public static void main(String[] args) {
A a1 = new A(); B b1 = new A();
C c1 = new A(); C c2 = new C();
c2.m1(a1); c2.m1(b1); c2.m1(c1);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: AAA |
| b. | Prints: ABC |
| c. | Prints: CCC |
| d. | Compile-time error |
| e. | Run-time error |
| f. | None of the above |
abstract class D {
String s1 = "D"; String getS1() {return s1;}
}
class E extends D {
String s1 = "E"; String getS1() {return s1;}
}
class F {
public static void main (String[] s) {
D x = new E();
System.out.print(x.s1 + x.getS1());
}}
What is the result of attempting to compile and run the program?
| a. | Prints: DD |
| b. | Prints: DE |
| c. | Prints: ED |
| d. | Prints: EE |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class A {void m1(A a) {System.out.print("A");}}
class B extends A {void m1(B b) {System.out.print("B");}}
class C extends B {void m1(C c) {System.out.print("C");}}
class D {
public static void main(String[] args) {
A a1 = new A(); B b1 = new B();
C c1 = new C(); C c2 = new A();
c2.m1(a1); c2.m1(b1); c2.m1(c1);
}
}
What is the result of attempting to compile and run the program?
| a. | Prints: AAA |
| b. | Prints: ABC |
| c. | Prints: CCC |
| d. | Compile-time error |
| e. | Run-time error |
| f. | None of the above |
class A {static void m() {System.out.print("A");}}
class B extends A {static void m() {System.out.print("B");}}
class C extends B {static void m() {System.out.print("C");}}
class D {
public static void main(String[] args) {
C c = new C();
c.m(); B b = c; b.m(); A a = b; a.m();
}}
What is the result of attempting to compile and run the program?
| a. | Prints: AAA |
| b. | Prints: ABC |
| c. | Prints: CBA |
| d. | Prints: CCC |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class A {String s1 = "A";}
class B extends A {String s1 = "B";}
class C extends B {String s1 = "C";}
class D {
static void m1(A x) {System.out.print(x.s1);}
static void m1(B x) {System.out.print(x.s1);}
static void m1(C x) {System.out.print(x.s1);}
public static void main(String[] args) {
A a; B b; C c; a = b = c = new C();
m1(a); m1(b); m1(c);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: AAA |
| b. | Prints: ABC |
| c. | Prints: CBA |
| d. | Prints: CCC |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |