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. | A class that implements an interface must implement all of the methods declared within the interface. |
| e. | None of the above. |
Which of the following are true statements?
| a. | Encapsulation is a form of data hiding. |
| b. | A tightly encapsulated class is always immutable. |
| c. | Encapsulation is always used to make programs run faster. |
| d. | Encapsulation helps to protect data from corruption. |
| e. | Encapsulation allows for changes to the internal design of a class while the public interface remains unchanged. |
Which of the following statements are true?
| a. | A constructor can invoke another constructor of the same class using the alternate constructor invocation, "this(argumentListopt);". |
| b. | A constructor can invoke itself using the alternate constructor invocation, "this(argumentListopt);". |
| c. | The alternate constructor invocation, "this(argumentListopt);", can legally appear anywhere in the constructor body. |
| d. | A constructor can invoke the constructor of the direct superclass using the superclass constructor invocation, "super(argumentListopt);". |
| e. | The number of constructor invocations that may appear in any constructor body can equal but not exceed the number of alternate constructors declared in the same class. |
| f. | A constructor is not permitted to throw an exception. |
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 true statements?
| a. | A top-level class can not be called "tightly encapsulated" unless it is declared private. |
| b. | Encapsulation enhances the maintainability of the code. |
| c. | A tightly encapsulated class allows fast public access to member fields. |
| d. | A tightly encapsulated class allows access to data only through accessor and mutator methods. |
| e. | Encapsulation usually reduces the size of the code. |
| f. | A tightly encapsulated class might have mutator methods that validate data before it is loaded into the internal data model. |
Suppose that the superclass constructor invocation, "super(argumentListopt);", appears explicitly in a subclass constructor. If a compile-time error is to be avoided then the arguments for the superclass constructor invocation, "super(argumentListopt);", can not refer to which of the following?
| a. | Static variables declared in this class or any superclass. |
| b. | Instance variables declared in this class or any superclass. |
| c. | Static methods declared in this class or any superclass. |
| d. | Instance methods declared in this class or any superclass. |
| e. | The keyword this. |
| f. | The keyword super. |
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 |
A class can not be called "tightly encapsulated" unless which of the following is true?
| a. | The class is declared final. |
| b. | All local variables are declared private. |
| c. | All method parameters are declared final. |
| d. | No method returns a reference to any object that is referenced by an internal data member. |
| e. | None of the above |
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 |
A class can not be called "tightly encapsulated" unless which of the following is true?
| a. | All of the methods are declared private. |
| b. | All of the methods are synchronized. |
| c. | All local variables are declared final. |
| d. | The class is a direct subclass of Object. |
| e. | Accessor methods are used to prevent fields from being set with invalid data. |
| f. | None of the above |
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. |
A class can not be called "tightly encapsulated" unless which of the following are true?
| a. | The data members can not be directly manipulated by external code. |
| b. | The class is declared final. |
| c. | It has no public mutator methods. |
| d. | The superclass is tightly encapsulated. |
class A {
String s1 = "A.s1"; String s2 = "A.s2";
}
class B extends A {
String s1 = "B.s1";
public static void main(String args[]) {
B x = new B(); A y = (A)x;
System.out.println(x.s1+" "+x.s2+" "+y.s1+" "+y.s2);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: B.s1 A.s2 B.s1 A.s2 |
| b. | Prints: B.s1 A.s2 A.s1 A.s2 |
| c. | Prints: A.s1 A.s2 B.s1 A.s2 |
| d. | Prints: A.s1 A.s2 A.s1 A.s2 |
| 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 extends C {
void m1(D d) {System.out.print("D");}
public static void main(String[] args) {
A a1 = new A(); B b1 = new B();
C c1 = new C(); D d1 = new D();
d1.m1(a1); d1.m1(b1); d1.m1(c1);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: AAA |
| b. | Prints: ABC |
| c. | Prints: DDD |
| d. | Prints: ABCD |
| e. | Compile-time error |
| f. | Run-time error |
| g. | None of the above |
class C {
void printS1() {System.out.print("C.printS1 ");}
static void printS2() {System.out.print("C.printS2 ");}
}
class D extends C {
void printS1(){System.out.print("D.printS1 ");}
void printS2() {System.out.print("D.printS2 ");}
public static void main (String args[]) {
C c = new D(); c.printS1(); c.printS2();
}}
What is the result of attempting to compile and run the program?
| a. | Prints: C.printS1 C.printS2 |
| b. | Prints: C.printS1 D.printS2 |
| c. | Prints: D.printS1 C.printS2 |
| d. | Prints: D.printS1 D.printS2 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class A {}
class B extends A {}
class C extends B {}
class D {
void m1(A a) {System.out.print("A");}
void m1(B b) {System.out.print("B");}
void m1(C c) {System.out.print("C");}
public static void main(String[] args) {
A c1 = new C(); B c2 = new C();
C c3 = new C(); D d1 = new D();
d1.m1(c1); d1.m1(c2); d1.m1(c3);
}}
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 E {
void printS1(){System.out.print("E.printS1 ");}
static void printS2() {System.out.print("E.printS2");}
}
class F extends E {
void printS1(){System.out.print("F.printS1 ");}
static void printS2() {System.out.print("F.printS2");}
public static void main (String args[]) {
E x = new F(); x.printS1(); x.printS2();
}}
What is the result of attempting to compile and run the program?
| a. | Prints: E.printS1 E.printS2 |
| b. | Prints: E.printS1 F.printS2 |
| c. | Prints: F.printS1 E.printS2 |
| d. | Prints: F.printS1 F.printS2 |
| 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 c1 = new C(); B c2 = new C();
C c3 = new C(); C c4 = new C();
c4.m1(c1); c4.m1(c2); c4.m1(c3);
}}
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 P {
static void printS1(){System.out.print("P.printS1 ");}
void printS2() {System.out.print("P.printS2 ");}
void printS1S2(){printS1();printS2();}
}
class Q extends P {
static void printS1(){System.out.print("Q.printS1 ");}
void printS2(){System.out.print("Q.printS2 ");}
public static void main(String[] args) {
new Q().printS1S2();
}}
What is the result of attempting to compile and run the program?
| a. | Prints: P.printS1 P.printS2 |
| b. | Prints: P.printS1 Q.printS2 |
| c. | Prints: Q.printS1 P.printS2 |
| d. | Prints: Q.printS1 Q.printS2 |
| 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 c1 = new C(); C c2 = new C(); c1.m1(c2);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: A |
| b. | Prints: B |
| c. | Prints: C |
| d. | Compile-time error |
| e. | Run-time error |
| f. | None of the above |
class R {
private void printS1(){System.out.print("R.printS1 ");}
protected void printS2() {System.out.print("R.printS2 ");}
protected void printS1S2(){printS1();printS2();}
}
class S extends R {
private void printS1(){System.out.print("S.printS1 ");}
protected void printS2(){System.out.print("S.printS2 ");}
public static void main(String[] args) {
new S().printS1S2();
}}
What is the result of attempting to compile and run the program?
| a. | Prints: R.printS1 R.printS2 |
| b. | Prints: R.printS1 S.printS2 |
| c. | Prints: S.printS1 R.printS2 |
| d. | Prints: S.printS1 S.printS2 |
| 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(); A b1 = new B();
A c1 = new C(); C c4 = new C();
a1.m1(c4); b1.m1(c4); c1.m1(c4);
}}
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 |