Test 13 Key
Test 13 Key
(A) collection
(B) list
### (C) set
(D) interface
(E) class
03. A(n) _______ is a linear collection that allows access to any element. Duplicates may exist.
(A) collection
### (B) list
(C) set
(D) interface
(E) class
(A) interface.
### (B) subinterface.
(C) abstract class.
(D) concrete class.
(E) subclass.
(A) interface.
### (B) subinterface.
(C) abstract class.
(D) concrete class.
(E) subclass.
(A) interface.
(B) subinterface.
(C) abstract class.
### (D) concrete class.
(E) subclass.
(A) interface.
(B) subinterface.
(C) abstract class.
### (D) concrete class.
(E) subclass.
(A) interface.
(B) subinterface.
(C) abstract class.
### (D) concrete class.
(E) subclass.
(A) interface.
(B) subinterface.
(C) abstract class.
### (D) concrete class.
(E) subclass.
interface Bank
{
public double getCheckingBalance();
public void makeCheckingDeposit(double amount);
public void makeCheckingWithdrawal(double amount);
}
11. What is the output of this program, if the MyBank class implements the Bank interface in this way?
###
(A) Tom's checking balance: 3000 (B) Tom's checking balance: 3000
Tom's checking balance: 2000 Tom's checking balance: 4000
Tom's checking balance: 7000 Tom's checking balance: -1000
(C) Tom's checking balance: 3000 (D) Tom's checking balance: 3000
Tom's checking balance: 4000 Tom's checking balance: 4000
Tom's checking balance: 9000 Tom's checking balance: 4000
###
(A) Tom's checking balance: 3000 (B) Tom's checking balance: 3000
Tom's checking balance: 2000 Tom's checking balance: 4000
Tom's checking balance: 7000 Tom's checking balance: -1000
(C) Tom's checking balance: 3000 (D) Tom's checking balance: 3000
Tom's checking balance: 4000 Tom's checking balance: 4000
Tom's checking balance: 9000 Tom's checking balance: 4000
(B) No
14. If the MyBank class implements the Bank interface with these methods, will the program compile?
(A) Yes
### (B) No
###
(A) Tom's checking balance: 4000 (C) Tom's checking balance: 6000
Tom's checking balance: 5000 Tom's checking balance: 9000
Tom's checking balance: 3000 Tom's checking balance: 5000
(B) Tom's checking balance: 4000 (D) Tom's checking balance: 6000
Tom's checking balance: 3000 Tom's checking balance: 5000
Tom's checking balance: 5000 Tom's checking balance: 9000
16. You want to add a method called transferToChecking that will transfer a specific amount of money from
the savings account to the checking account.
Which of the following methods is the BEST implementation for this method?
(A) (B)
public void transferToChecking(double amount) public void transferToChecking(double amount)
{ {
checking -= amount; checking += amount;
savings += amount; savings -= amount;
} }
(C)### (D)
public void transferToChecking(double amount) public void transferToChecking(double amount)
{ {
if (savings >= amount) if (savings > amount)
{ {
checking += amount; checking += amount;
savings -= amount; savings -= amount;
} }
else }
System.out.println("Insufficient Funds");
}
public MyBank(double c)
{
checking = c;
interest = 0.0;
// rate = 0.1;
}
(B) No
18. Will the program on the previous page compile if the keyword final is removed from the Bank interface?
(B) No
19. Will the program on the previous page compile if the comment symbol (//) is removed from the MyBank
constructor statement // rate = 0.1?
(A) Yes
### (B) No
20. Will the program on the previous page compile if the keyword final is removed from the Bank interface
and the comment symbol (//) is removed from the MyBank constructor?
(A) Yes
### (B) No
26. What would be the result of changing the keyword extends to implements in the definition
of MyBank?
I. concrete classes
II. interfaces
III. abstract classes
(A) I only
(B) II only
(C) III only
### (D) II and III only
(E) I, II and III
28. Suppose that you run a travel agency specializing in European travel and you want to create
an administrative travel program to keep track of the different aspects of a client's travel.
The program starts with the design of an interface to specify the required operations.
###(A) (B)
interface Europe abstract interface Europe
{ {
public void flights(); public abstract String clientName = "Smith";
public void railpass(); public abstract void flights();
public void documentation(); public abstract void railpass();
public void money(); public abstract void documentation();
public void hotels(); public abstract void money();
public void excursions(); public abstract void hotels();
public void phrases(); public abstract void excursions();
} public abstract void phrases();
}
(C) (D)
interface Europe interface Europe
{ {
public String clientName; public Travel() { }
Which of the following is an abstract class that will properly implement the common methods?
(Note for experienced travelers. Yes there are different Eurail Passes. For this question there is only one.)
(A) (B)
abstract class WestEurope implements Europe class WestEurope implements Europe
{ {
public abstract void railpass() public void railpass()
{ /* assume method is implemented */ } { /* assume method is implemented */ }
(C) ###(D)
class WestEurope implements Europe abstract class WestEurope implements Europe
{ {
public void railpass() public void railpass()
{ /* assume method is implemented */ } { /* assume method is implemented */ }
Which of the following is a concrete class that will properly implement the abstract methods?
###(A) (B)
class Italy extends WestEurope class Italy extends WestEurope
{ {
private String clientName; private String clientName;
(C) (D)
class Italy implements WestEurope class Italy
{ {
private String clientName; private String clientName;
interface Qwerty
{
public void qwertyA();
public void qwertyB();
public void qwertyC();
public void qwertyD();
public void qwertyE();
public void qwertyF();
public void qwertyG();
public void qwertyH();
}
31. The Qwerty interface contains 8 practical methods for various utility purposes.
Your new program only requires only the use of method qwertyA.
Which of the following concrete classes properly uses the Qwerty interface?
(A) (B)
class Q31 implements Qwerty class Q31 implements Qwerty
{ {
public void qwertyA() public void qwertyA()
{ {
/* assume method qwertyA is implemented */ /* assume method qwertyA is implemented */
} }
}
public abstract void qwertyB() { }
public abstract void qwertyC() { }
public abstract void qwertyD() { }
public abstract void qwertyE() { }
public abstract void qwertyF() { }
public abstract void qwertyG() { }
public abstract void qwertyH() { }
}
###(C) (D)
class Q31 implements Qwerty class Q31 extends Qwerty
{ {
public void qwertyA() public void qwertyA()
{ {
/* assume method qwertyA is implemented */ /* assume method qwertyA is implemented */
} }
###(A) (B)
abstract class Qwerty2 implements Qwerty abstract class Qwerty2 extends Qwerty
{ {
public void qwertyA() { } public void qwertyA() { }
public void qwertyB() { } public void qwertyB() { }
public void qwertyC() { } public void qwertyC() { }
public void qwertyD() { } public void qwertyD() { }
public void qwertyE() { } public void qwertyE() { }
public void qwertyF() { } public void qwertyF() { }
public void qwertyG() { } public void qwertyG() { }
public void qwertyH() { } public void qwertyH() { }
} }
(C) (D)
abstract class Qwerty2 implements Qwerty abstract class Qwerty2 extends Qwerty
{ {
public abstract void qwertyA() { } public abstract void qwertyA() { }
public abstract void qwertyB() { } public abstract void qwertyB() { }
public abstract void qwertyC() { } public abstract void qwertyC() { }
public abstract void qwertyD() { } public abstract void qwertyD() { }
public abstract void qwertyE() { } public abstract void qwertyE() { }
public abstract void qwertyF() { } public abstract void qwertyF() { }
public abstract void qwertyG() { } public abstract void qwertyG() { }
public abstract void qwertyH() { } public abstract void qwertyH() { }
} }
33. The special abstract class that facilitates using an interfaces, when only a few methods are implemented
is called a(n)
(A) ###(B)
class Q31 implements Qwerty class Q31 implements Qwerty
{ {
public void qwertyA() public void qwertyA()
{ {
/* assume method qwertyA is implemented */ /* assume method qwertyA is implemented */
} }
}
public abstract void qwertyB() { }
public abstract void qwertyC() { }
public abstract void qwertyD() { }
public abstract void qwertyE() { }
public abstract void qwertyF() { }
public abstract void qwertyG() { }
public abstract void qwertyH() { }
}
(C) (D)
class Q31 implements Qwerty class Q31 extends Qwerty
{ {
public void qwertyA() public void qwertyA()
{ {
/* assume method qwertyA is implemented */ /* assume method qwertyA is implemented */
} }
interface List<E>
{
public int Size();
// returns the number of elements in list
(A) inheritance.
(B) composition.
(C) polymorphism.
### (D) generics.
(E) All of the above