Deck 10: Interfaces
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/100
Play
Full screen (f)
Deck 10: Interfaces
1
Consider the following declarations:
Which of the following method headers should be used to complete the SecretText class?
A.public void encrypt()
B.void encrypt(String aKey)
C.public void encrypt(String aKey)
D.public String encrypt(String aKey)

A.public void encrypt()
B.void encrypt(String aKey)
C.public void encrypt(String aKey)
D.public String encrypt(String aKey)
public void encrypt(String aKey)
2
Which statement about methods in an interface is true?
A.All methods in an interface must be explicitly declared as private or public.
B.All methods in an interface are automatically public.
C.All methods in an interface are automatically private.
D.All methods in an interface are automatically static.
A.All methods in an interface must be explicitly declared as private or public.
B.All methods in an interface are automatically public.
C.All methods in an interface are automatically private.
D.All methods in an interface are automatically static.
All methods in an interface are automatically public.
3
Which of the following statements about interfaces is NOT true?
A.Interfaces can reduce the coupling between classes.
B.A class can implement only one interface type.
C.An interface cannot have instance variables.
D.Interfaces can make code more reusable.
A.Interfaces can reduce the coupling between classes.
B.A class can implement only one interface type.
C.An interface cannot have instance variables.
D.Interfaces can make code more reusable.
A class can implement only one interface type.
4
Consider the following code snippet:
Which of the following statements is true?
A.LARGE_CHANGE and SMALL_CHANGE are instance variables.
B.LARGE_CHANGE and SMALL_CHANGE are automatically public static final.
C.LARGE_CHANGE and SMALL_CHANGE must be defined with the keywords private static final.
D.LARGE_CHANGE and SMALL_CHANGE must be defined with the keywords public static final.

A.LARGE_CHANGE and SMALL_CHANGE are instance variables.
B.LARGE_CHANGE and SMALL_CHANGE are automatically public static final.
C.LARGE_CHANGE and SMALL_CHANGE must be defined with the keywords private static final.
D.LARGE_CHANGE and SMALL_CHANGE must be defined with the keywords public static final.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following statements about interfaces is NOT true?
A.An interface can supply a default implementation.
B.Interfaces can make code more reusable.
C.An interface can describe the state that should be maintained.
D.An interface describes the behavior that an implementation should supply.
A.An interface can supply a default implementation.
B.Interfaces can make code more reusable.
C.An interface can describe the state that should be maintained.
D.An interface describes the behavior that an implementation should supply.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
6
Suppose you are writing an interface called Resizable, which includes one void method called resize that accepts no parameters. 

Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
7
Consider the definition of the Measurable interface and the code snippet defining the Inventory class:
Why is it necessary to declare getMeasure as public in the Inventory class?
A.It is necessary only to allow other classes to use this method.
B.It is not necessary to declare this method as public.
C.All methods in an interface are private by default.
D.All methods in a class are not public by default.

A.It is necessary only to allow other classes to use this method.
B.It is not necessary to declare this method as public.
C.All methods in an interface are private by default.
D.All methods in a class are not public by default.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
8
Using the following definitions of the Measurable and Named interfaces.
Assume BankAccount provides the code for the getMeasure() and getName() methods.Which of the following could correctly represent the class header for BankAccount?
A.public class BankAccount extends Measurable implements Named
B.public class BankAccount implements Measurable, Named
C.public interface BankAccount implements Measurable, Named
D.public class BankAccount extends Measurable, Named

A.public class BankAccount extends Measurable implements Named
B.public class BankAccount implements Measurable, Named
C.public interface BankAccount implements Measurable, Named
D.public class BankAccount extends Measurable, Named
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
9
What type of edge does UML use to denote interface implementation?
A.A dotted arrow from the interface to the class terminated with a triangular tip.
B.A dotted arrow from the class to the interface terminated with an open arrow tip.
C.A dotted arrow from the interface to the class terminated with an open arrow tip.
D.A dotted arrow from the class to the interface terminated with a triangular tip.
A.A dotted arrow from the interface to the class terminated with a triangular tip.
B.A dotted arrow from the class to the interface terminated with an open arrow tip.
C.A dotted arrow from the interface to the class terminated with an open arrow tip.
D.A dotted arrow from the class to the interface terminated with a triangular tip.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
10
A class that implements an interface must provide an implementation for all ____ methods.
A.private
B.final
C.static
D.abstract
A.private
B.final
C.static
D.abstract
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
11
Consider the following code snippet:
Which of the following completes the interface declaration correctly?
A.final
B.private
C.static
D.public

A.final
B.private
C.static
D.public
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
12
To use an interface, a class header should include which of the following?
A.The keyword extends and the name of the interface
B.The keyword extends and the name of an abstract method in the interface
C.The keyword implements and the name of an abstract method in the interface
D.The keyword implements and the name of the interface
A.The keyword extends and the name of the interface
B.The keyword extends and the name of an abstract method in the interface
C.The keyword implements and the name of an abstract method in the interface
D.The keyword implements and the name of the interface
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
13
Consider the definition of the Measurable interface and the code snippet defining the Inventory class:
The compiler complains that the getMeasure method has a weaker access level than the Measurable interface.Why?
A.The getMeasure method was declared as private in the Measurable interface.
B.The variable onHandCount was not declared with public access.
C.All of the methods in a class have a default access level of package access, while the methods of an interface have a default access level of private.
D.All of the methods in a class have a default access level of package access, while the methods of an interface have a default access level of public.

A.The getMeasure method was declared as private in the Measurable interface.
B.The variable onHandCount was not declared with public access.
C.All of the methods in a class have a default access level of package access, while the methods of an interface have a default access level of private.
D.All of the methods in a class have a default access level of package access, while the methods of an interface have a default access level of public.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
14
In UML, a dotted arrow with a triangular tip denotes ____________________.
A.interface implementation
B.dependency
C.inheritance
D.aggregation
A.interface implementation
B.dependency
C.inheritance
D.aggregation
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following statements about an interface is true?
A.An interface has both public and private methods.
B.An interface has methods and instance variables.
C.An interface has methods but no instance variables.
D.An interface has neither methods nor instance variables.
A.An interface has both public and private methods.
B.An interface has methods and instance variables.
C.An interface has methods but no instance variables.
D.An interface has neither methods nor instance variables.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following statements is correct about inheritance and interfaces?
A.A class can extend multiple classes and can implement multiple interfaces.
B.A class can extend at most one class and can implement at most one interface.
C.A class can extend multiple classes and can implement at most one interface.
D.A class can extend at most one class and can implement multiple interfaces.
A.A class can extend multiple classes and can implement multiple interfaces.
B.A class can extend at most one class and can implement at most one interface.
C.A class can extend multiple classes and can implement at most one interface.
D.A class can extend at most one class and can implement multiple interfaces.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
17
Consider the definition of the Measurable interface and the code snippet defining the Inventory class:
What is wrong with this code?
A.The getMeasure() method must be declared as private.
B.The getMeasure() method must be declared as public.
C.The getMeasure() method must include the implements keyword.
D.The getMeasure() method must not have any code within it.

A.The getMeasure() method must be declared as private.
B.The getMeasure() method must be declared as public.
C.The getMeasure() method must include the implements keyword.
D.The getMeasure() method must not have any code within it.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
18
A method that has no implementation is called a/an ____ method.
A.abstract
B.overloaded
C.interface
D.implementation
A.abstract
B.overloaded
C.interface
D.implementation
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following statements about abstract methods is true?
A.An abstract method has only a name and a return type, but no parameters or code in its body.
B.An abstract method has a name, a return type, and code in its body, but has no parameters.
C.An abstract method has parameters, a return type, and code in its body, but has no defined name.
D.An abstract method has a name, parameters, and a return type, but no code in the body of the method.
A.An abstract method has only a name and a return type, but no parameters or code in its body.
B.An abstract method has a name, a return type, and code in its body, but has no parameters.
C.An abstract method has parameters, a return type, and code in its body, but has no defined name.
D.An abstract method has a name, parameters, and a return type, but no code in the body of the method.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following statements about a Java interface is NOT true?
A.A Java interface must contain more than one method.
B.A Java interface defines a set of methods that are required.
C.A Java interface specifies behavior that a class will implement.
D.All methods in a Java interface must be public.
A.A Java interface must contain more than one method.
B.A Java interface defines a set of methods that are required.
C.A Java interface specifies behavior that a class will implement.
D.All methods in a Java interface must be public.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
21
Assume a class extends another class and implements an interface, both of which define the same method.Which statement is true about this conflict of inherited methods?
A.The compiler will generate an error due to the conflict.
B.The code compiles but generates an exception at run time due to the conflict.
C.The subclass inherits the superclass method and ignores the default method from the interface.
D.There is no conflict because interfaces cannot provide method implementation.
A.The compiler will generate an error due to the conflict.
B.The code compiles but generates an exception at run time due to the conflict.
C.The subclass inherits the superclass method and ignores the default method from the interface.
D.There is no conflict because interfaces cannot provide method implementation.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
22
Using the given definition of the Measurable interface:
Which of the following statements is true?
A.The code does not compile because a variable of type Measurable does not have a getBalance method.
B.The code compiles but generates an exception at run time because a Measurable object reference does not have a getBalance method.
C.The code executes, displaying the balance of the bank account.
D.The code does not compile because you cannot assign a BankAccount object to a variable of type Measurable.

A.The code does not compile because a variable of type Measurable does not have a getBalance method.
B.The code compiles but generates an exception at run time because a Measurable object reference does not have a getBalance method.
C.The code executes, displaying the balance of the bank account.
D.The code does not compile because you cannot assign a BankAccount object to a variable of type Measurable.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
23
Consider the following class:
Which is the best statement to use to complete the compareTo() method?
A.return Integer.compare(otherTemp.value, value)
B.return (value - otherTemp.value)
C.return (otherTemp.value - value)
D.return Integer.compare(value, otherTemp.value)

A.return Integer.compare(otherTemp.value, value)
B.return (value - otherTemp.value)
C.return (otherTemp.value - value)
D.return Integer.compare(value, otherTemp.value)
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
24
Which of the following can potentially be changed when implementing an interface?
A.The return type of a method in the interface.
B.The types of parameters of a method in the interface.
C.The name of a method in the interface.
D.You cannot change the name, return type, or types of parameters of a method in the interface.
A.The return type of a method in the interface.
B.The types of parameters of a method in the interface.
C.The name of a method in the interface.
D.You cannot change the name, return type, or types of parameters of a method in the interface.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
25
Assume a class implements two interfaces, both of which define a default method with the same signature.Which statement is true about this conflict of inherited methods?
A.The code compiles but generates an exception at run time due to the conflict.
B.The code compiles and the implementation is chosen at run time.
C.The class must override the method and provide its own implementation.
D.There is no conflict because interfaces cannot provide method implementation.
A.The code compiles but generates an exception at run time due to the conflict.
B.The code compiles and the implementation is chosen at run time.
C.The class must override the method and provide its own implementation.
D.There is no conflict because interfaces cannot provide method implementation.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following is true about interface types and abstract classes?
A.An interface type cannot be instantiated whereas an abstract class can.
B.An interface type cannot have instance variables whereas an abstract class can.
C.An abstract class can provide method implementation whereas an interface type cannot.
D.An interface type cannot have constants whereas an abstract class can.
A.An interface type cannot be instantiated whereas an abstract class can.
B.An interface type cannot have instance variables whereas an abstract class can.
C.An abstract class can provide method implementation whereas an interface type cannot.
D.An interface type cannot have constants whereas an abstract class can.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
27
Assume that the Measurable interface is defined with a static sum method that computes the sum of the Measurable objects passed in as an array, and that BankAccount implements the Measurable interface.Also assume that there is a variable branchAccounts that is an object reference to a populated array of BankAccount objects for a bank branch.Which of the following represents a correct invocation of the sum method to find the total balance of all accounts at the branch?
A.Arrays.sum(branchAccounts)
B.BankAccount.sum(branchAccounts)
C.Measurable.sum(branchAccounts)
D.branchAccounts.sum()
A.Arrays.sum(branchAccounts)
B.BankAccount.sum(branchAccounts)
C.Measurable.sum(branchAccounts)
D.branchAccounts.sum()
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
28
The method below is designed to return the smaller of two Comparable objects received as arguments.Assume that the objects are instances of the same class.Select the correct expression to complete the method.
A.value1.compareTo(value2) > 0
B.value1 < value2
C.value1.compareTo(value2) < 0
D.value1.compareTo(value2) == 0

A.value1.compareTo(value2) > 0
B.value1 < value2
C.value1.compareTo(value2) < 0
D.value1.compareTo(value2) == 0
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
29
Using the given definition of the Measurable interface:
Which of the following statements is true?
A.The code executes, displaying the measure of the Measurable object.
B.The code does not compile because interface types cannot be instantiated.
C.The code compiles but generates an exception at run time because getMeasure does not return a String.
D.The code compiles but generates an exception at run time because m does not reference a BankAccount object.

A.The code executes, displaying the measure of the Measurable object.
B.The code does not compile because interface types cannot be instantiated.
C.The code compiles but generates an exception at run time because getMeasure does not return a String.
D.The code compiles but generates an exception at run time because m does not reference a BankAccount object.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following is true about a default method in an interface declaration?
A.A default method is a static method that does not have an implicit parameter.
B.A default method does not provide an implementation.
C.A class that implements the interface cannot override the default behavior.
D.A class that implements the interface can inherit the default behavior.
A.A default method is a static method that does not have an implicit parameter.
B.A default method does not provide an implementation.
C.A class that implements the interface cannot override the default behavior.
D.A class that implements the interface can inherit the default behavior.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
31
Consider the following class:
What statement can be used to complete the compareTo() method?
A.otherGame.score - score
B.return (otherGame.score - score)
C.score - otherGame.score
D.return (score - otherGame.score)

A.otherGame.score - score
B.return (otherGame.score - score)
C.score - otherGame.score
D.return (score - otherGame.score)
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
32
Consider the following code snippet:
Which of the following completes the interface declaration correctly?
A.public
B.private
C.final
D.default

A.public
B.private
C.final
D.default
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
33
Which of the following is true regarding a class and interface types?
A.You can convert from a class type to any interface type that the class extends.
B.You cannot convert from a class type to any interface type.
C.You can convert from a class type to any interface type that the class implements.
D.You can convert from a class type to any interface type that is in the same package as the class.
A.You can convert from a class type to any interface type that the class extends.
B.You cannot convert from a class type to any interface type.
C.You can convert from a class type to any interface type that the class implements.
D.You can convert from a class type to any interface type that is in the same package as the class.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
34
Using the given definition of the Measurable interface:
Select the correct expression to display the balance of the bank account.
A.m.BankAccount.getBalance()
B.m.getBalance()
C.((BankAccount) m).getBalance()
D.m.super.getBalance()

A.m.BankAccount.getBalance()
B.m.getBalance()
C.((BankAccount) m).getBalance()
D.m.super.getBalance()
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
35
Which of the following statements about interfaces is true?
A.You cannot define a variable whose type is an interface.
B.You can define an interface variable that refers to an object of any class in the same package.
C.You can define an interface variable that refers to an object only if the object belongs to a class that implements the interface.
D.You can instantiate an object from an interface class.
A.You cannot define a variable whose type is an interface.
B.You can define an interface variable that refers to an object of any class in the same package.
C.You can define an interface variable that refers to an object only if the object belongs to a class that implements the interface.
D.You can instantiate an object from an interface class.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
36
Consider the following class:
What statement can be used to complete the compareTo() method?
A.Player otherPlayer = (Player) otherObject;
B.Object otherPlayer = (Player) otherObject;
C.Object otherPlayer = otherObject;
D.Player otherPlayer = otherObject;

A.Player otherPlayer = (Player) otherObject;
B.Object otherPlayer = (Player) otherObject;
C.Object otherPlayer = otherObject;
D.Player otherPlayer = otherObject;
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
37
Which of the following are not allowed in a Java 8 interface declaration?
A.instance variables
B.default methods
C.static methods
D.constants
A.instance variables
B.default methods
C.static methods
D.constants
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
38
Consider the following code snippet. 

Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
39
If you have multiple classes in your program that have implemented the same interface in
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
40
Consider the following declarations:
A.increaseSize()
B.decreaseSize()
C.display(5)
D.display()

A.increaseSize()
B.decreaseSize()
C.display(5)
D.display()
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
41
You wish to implement a callback method for an object created from a library class that you cannot change.What is the preferred way to accomplish this?
A.Extend the library class.
B.Use an inner class in the interface.
C.Create a new class that mimics the library class.
D.Use a helper class that implements the callback method.
A.Extend the library class.
B.Use an inner class in the interface.
C.Create a new class that mimics the library class.
D.Use a helper class that implements the callback method.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
42
Consider the following class:
Which is the best statement to use to complete the compareTo() method?
A.return (otherStock.price - price)
B.return Integer.compare(price, otherStock.price)
C.return Double.compare(otherStock.price, price)
D.return Double.compare(price, otherStock.price)

A.return (otherStock.price - price)
B.return Integer.compare(price, otherStock.price)
C.return Double.compare(otherStock.price, price)
D.return Double.compare(price, otherStock.price)
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
43
Which of the following statements about lambda expressions is NOT true?
A.Lambda expressions are used to define a single function of a functional interface.
B.A lambda expression defines the parameters and return value of a method in a compact notation.
C.Lambda expressions are a convenient notation for callbacks.
D.Lambda expressions cannot contain a method body enclosed in braces with a return statement.
A.Lambda expressions are used to define a single function of a functional interface.
B.A lambda expression defines the parameters and return value of a method in a compact notation.
C.Lambda expressions are a convenient notation for callbacks.
D.Lambda expressions cannot contain a method body enclosed in braces with a return statement.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
44
What role does an interface play when using a mock class?
A.An interface should be implemented by both the real class and the mock class to guarantee that the mock class accurately simulates the real class when used in a program.
B.The mock class should be an interface that will be implemented by the real class.
C.Interfaces are not involved when using mock classes.
D.The real class should be an interface that will be implemented by the mock class.
A.An interface should be implemented by both the real class and the mock class to guarantee that the mock class accurately simulates the real class when used in a program.
B.The mock class should be an interface that will be implemented by the real class.
C.Interfaces are not involved when using mock classes.
D.The real class should be an interface that will be implemented by the mock class.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
45
An ____ belongs to a class whose methods describe the actions to be taken when a user clicks a user-interface graphical object.
A.event source
B.event listener
C.action method
D.action listener
A.event source
B.event listener
C.action method
D.action listener
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
46
Which of the following statements about an inner class is true?
A.An inner class is used for a utility class that should be visible elsewhere in the program.
B.An inner class that is defined inside a method is publicly accessible.
C.An inner class that is defined inside a method is not publicly accessible.
D.An inner class that is defined inside an enclosing class but outside of its methods is not available to all methods of the enclosing class.
A.An inner class is used for a utility class that should be visible elsewhere in the program.
B.An inner class that is defined inside a method is publicly accessible.
C.An inner class that is defined inside a method is not publicly accessible.
D.An inner class that is defined inside an enclosing class but outside of its methods is not available to all methods of the enclosing class.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
47
Consider the following class:
Which of the following method headers should be used to complete the ClickListener class?
A.public void actionPerformed(ActionEvent event)
B.public void actionPerformed(ClickListener event)
C.public void actionPerformed()
D.public void actionPerformed(ActionListener event)

A.public void actionPerformed(ActionEvent event)
B.public void actionPerformed(ClickListener event)
C.public void actionPerformed()
D.public void actionPerformed(ActionListener event)
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
48
Which of the following statements about a mock class is true?
A.A mock class does not provide an implementation of the services of the actual class.
B.A mock class must be an interface.
C.A mock class provides a simplified implementation of the services of the actual class.
D.A mock class provides a complete implementation of the services of the actual class.
A.A mock class does not provide an implementation of the services of the actual class.
B.A mock class must be an interface.
C.A mock class provides a simplified implementation of the services of the actual class.
D.A mock class provides a complete implementation of the services of the actual class.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
49
Consider the following code snippet that uses the parameterized Comparable interface. 

Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
50
Which of the following statements about events and graphical user interface programs is true?
A.Your program must instruct the Java window manager to send it notifications about specific types of events to which the program wishes to respond.
B.The Java window manager will automatically send your program notifications about all events that have occurred.
C.Your program must override the default methods to handle events.
D.Your program must respond to notifications of all types of events that are sent to it by the Java window manager.
A.Your program must instruct the Java window manager to send it notifications about specific types of events to which the program wishes to respond.
B.The Java window manager will automatically send your program notifications about all events that have occurred.
C.Your program must override the default methods to handle events.
D.Your program must respond to notifications of all types of events that are sent to it by the Java window manager.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
51
Which of the following statements about a callback is NOT true?
A.A callback can be implemented using an interface.
B.A callback can allow you to implement a new method for a class that is not under your control.
C.A callback method declared in an interface must specify the class of objects that it will manipulate.
D.A callback is a mechanism for specifying code to be executed later.
A.A callback can be implemented using an interface.
B.A callback can allow you to implement a new method for a class that is not under your control.
C.A callback method declared in an interface must specify the class of objects that it will manipulate.
D.A callback is a mechanism for specifying code to be executed later.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
52
Consider the following code snippet:
Which of the following statements correctly clones the account?
A.BankAccount clonedAccount = Object.clone(account);
B.BankAccount clonedAccount = account.super.clone();
C.BankAccount clonedAccount = account.clone();
D.BankAccount clonedAccount = (BankAccount) account.clone();

A.BankAccount clonedAccount = Object.clone(account);
B.BankAccount clonedAccount = account.super.clone();
C.BankAccount clonedAccount = account.clone();
D.BankAccount clonedAccount = (BankAccount) account.clone();
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
53
Assuming that interface Resizable is declared elsewhere, consider the following class declaration:
Which of the following declarations can be used to complete the main method?
A.SizeModifier something = new Resizable();
B.Resizable something = new Resizable();
C.Resizable something = new InnerClassExample();
D.Resizable something = new SizeModifier();

A.SizeModifier something = new Resizable();
B.Resizable something = new Resizable();
C.Resizable something = new InnerClassExample();
D.Resizable something = new SizeModifier();
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
54
Which of the following is an event source?
A.An inner class.
B.An event listener.
C.A JButton object.
D.An event adapter.
A.An inner class.
B.An event listener.
C.A JButton object.
D.An event adapter.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
55
Which of the following correctly defines a functional interface that, given an object, returns the value of a Coin?
A.(Object obj) => ((Coin) obj).getValue()
B.(Object obj) -> (Coin) obj.getValue()
C.(Object obj) => (Coin) obj.getValue()
D.(Object obj) -> ((Coin) obj).getValue()
A.(Object obj) => ((Coin) obj).getValue()
B.(Object obj) -> (Coin) obj.getValue()
C.(Object obj) => (Coin) obj.getValue()
D.(Object obj) -> ((Coin) obj).getValue()
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
56
A/an ____ class defined in a method signals to the reader of your program that the class is not interesting beyond the scope of the method.
A.protected
B.interface
C.abstract
D.inner
A.protected
B.interface
C.abstract
D.inner
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
57
____ are generated when the user presses a key, clicks a button, or selects a menu item.
A.Errors
B.Interfaces
C.Events
D.Listeners
A.Errors
B.Interfaces
C.Events
D.Listeners
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
58
Consider the following code snippet:
myImage.add(new Rectangle(10,10,10,10));
This code is an example of using ____.
A.an anonymous class.
B.an abstract class.
C.an anonymous object.
D.an abstract object.
myImage.add(new Rectangle(10,10,10,10));
This code is an example of using ____.
A.an anonymous class.
B.an abstract class.
C.an anonymous object.
D.an abstract object.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
59
Which of the following statements about the Object.clone method is NOT true?
A.Its return type is the same as the cloned object.
B.It returns a new object that has a state identical to the cloned object.
C.If the object being cloned does not implement the Cloneable interface, then it throws an exception.
D.It does not clone mutable instance variables.
A.Its return type is the same as the cloned object.
B.It returns a new object that has a state identical to the cloned object.
C.If the object being cloned does not implement the Cloneable interface, then it throws an exception.
D.It does not clone mutable instance variables.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
60
Consider the following declarations:
What parameter declaration can be used to complete the callback measure method?
A.String aString
B.Object aString
C.Object anObject
D.String anObject

A.String aString
B.Object aString
C.Object anObject
D.String anObject
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
61
Consider the following code snippet which is supposed to show the total order amount when the button is clicked:
What is wrong with this code?
A.button should be declared as final
B.There is no error.
C.The listener cannot access the methods of the myOrder object.
D.The listener has not been attached to the button.

A.button should be declared as final
B.There is no error.
C.The listener cannot access the methods of the myOrder object.
D.The listener has not been attached to the button.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
62
Which of the following statements about an inner class is true?
A.An inner class may not be declared within a method of the enclosing scope.
B.The methods of an inner class can access variables declared in the enclosing scope.
C.An inner class may only be declared within a method of the enclosing scope.
D.An inner class can access variables from the enclosing scope only if they are passed as constructor or method parameters.
A.An inner class may not be declared within a method of the enclosing scope.
B.The methods of an inner class can access variables declared in the enclosing scope.
C.An inner class may only be declared within a method of the enclosing scope.
D.An inner class can access variables from the enclosing scope only if they are passed as constructor or method parameters.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
63
Which of the following is an example of a functional interface, having a single abstract method?
A.ActionListener
B.KeyListener
C.MouseListener
D.MouseAdapter
A.ActionListener
B.KeyListener
C.MouseListener
D.MouseAdapter
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
64
Event listeners are often installed as ____ classes so that they can have access to the surrounding fields, methods, and final variables.
A.interface
B.helper
C.inner
D.abstract
A.interface
B.helper
C.inner
D.abstract
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
65
Which of the following correctly completes the Java statement shown to add a listener to a button using a lambda expression?
button.addActionListener(_________________________________);
A.(ActionEvent event) => System.out.println("Clicked!")
B.lambda((ActionEvent event) -> System.out.println("Clicked!"))
C.(ActionEvent event) -> System.out.println("Clicked!")
D.lambda(ActionEvent event, System.out.println("Clicked!"))
button.addActionListener(_________________________________);
A.(ActionEvent event) => System.out.println("Clicked!")
B.lambda((ActionEvent event) -> System.out.println("Clicked!"))
C.(ActionEvent event) -> System.out.println("Clicked!")
D.lambda(ActionEvent event, System.out.println("Clicked!"))
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
66
When an event occurs, the event source notifies all ____.
A.event listeners
B.components
C.panels
D.interfaces
A.event listeners
B.components
C.panels
D.interfaces
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
67
To build a user interface that contains graphical components, the components ____.
A.must each be added to a separate panel.
B.must be added directly to a frame component.
C.must be added to a panel that is contained within a frame.
D.must be added to a frame that is contained within a panel.
A.must each be added to a separate panel.
B.must be added directly to a frame component.
C.must be added to a panel that is contained within a frame.
D.must be added to a frame that is contained within a panel.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
68
To associate an event listener with a JButton component, you must use the ___ method of the JButton class.
A.addActionListener
B.addButtonListener
C.addListener
D.addEventListener
A.addActionListener
B.addButtonListener
C.addListener
D.addEventListener
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
69
A ____ has an addActionListener() method for specifying which object is responsible for implementing the action associated with the object.
A.JSlider
B.JButton
C.JFrame
D.JLabel
A.JSlider
B.JButton
C.JFrame
D.JLabel
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
70
Listeners are typically implemented as inner classes.Which of the following statements is NOT true about inner class access to variables from the surrounding class?
A.Inner class objects created inside a static method can only access static variables.
B.Local variables that are accessed by an inner class method must not change after they have been initialized.
C.Methods of an inner class cannot access variables from the surrounding class.
D.An inner class can access instance variables of the surrounding class if the instance variable belongs to the object that constructed the inner class object.
A.Inner class objects created inside a static method can only access static variables.
B.Local variables that are accessed by an inner class method must not change after they have been initialized.
C.Methods of an inner class cannot access variables from the surrounding class.
D.An inner class can access instance variables of the surrounding class if the instance variable belongs to the object that constructed the inner class object.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
71
Consider the following code snippet:
Which of the following statements is correct?
A.A ClickListener object has been added as a listener for the action events that buttons generate.
B.Class ClickListener is an interface type.
C.Class ButtonTester implements an interface type.
D.Class ButtonTester is an interface type.

A.A ClickListener object has been added as a listener for the action events that buttons generate.
B.Class ClickListener is an interface type.
C.Class ButtonTester implements an interface type.
D.Class ButtonTester is an interface type.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
72
Consider the following code snippet:
Which of the following statements will complete this code?
A.java.swing.event.ActionEvent;.
B.javax.awt.event.ActionEvent;
C.java.awt.event.ActionEvent;
D.javax.swing.event.ActionEvent;

A.java.swing.event.ActionEvent;.
B.javax.awt.event.ActionEvent;
C.java.awt.event.ActionEvent;
D.javax.swing.event.ActionEvent;
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
73
To respond to a button event, a listener must supply instructions for the ____ method of the ActionListener interface.
A.eventAction
B.actionPerformed
C.actionEvent
D.eventResponse
A.eventAction
B.actionPerformed
C.actionEvent
D.eventResponse
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
74
Consider the following code snippet:
Which statement would add the panel to the frame?
A.frame.add(JPanel panel);
B.frame.addComponent(JPanel panel);
C.frame.add(panel);
D.frame.addComponent(panel);

A.frame.add(JPanel panel);
B.frame.addComponent(JPanel panel);
C.frame.add(panel);
D.frame.addComponent(panel);
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
75
Assuming that the ClickListener class implements the ActionListener interface, what statement should be used to complete the following code segment?
A.myButton.addActionListener(listener);
B.myPanel.addActionListener(myButton);
C.myPanel.addActionListener(listener);
D.myButton.addActionListener(ClickListener);

A.myButton.addActionListener(listener);
B.myPanel.addActionListener(myButton);
C.myPanel.addActionListener(listener);
D.myButton.addActionListener(ClickListener);
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
76
The methods of an ____ describe the actions to be taken when an event occurs.
A.event source
B.event interface
C.action source
D.event listener
A.event source
B.event interface
C.action source
D.event listener
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
77
Which of the following code statements creates a graphical button that has "Calculate" as its label ?
A.JButton button = new JButton().label("Calculate");
B.JButton button = new JButton().add("Calculate");
C.JButton button = new JButton("Calculate");
D.Button button = new Button("Calculate");
A.JButton button = new JButton().label("Calculate");
B.JButton button = new JButton().add("Calculate");
C.JButton button = new JButton("Calculate");
D.Button button = new Button("Calculate");
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
78
Which container is used to group multiple user-interface components together?
A.text area
B.rectangle
C.table
D.panel
A.text area
B.rectangle
C.table
D.panel
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
79
Which of the following correctly defines a ButtonListener as an inner class and creates an instance of ButtonListener as a listener for the button? 

Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck
80
How do you specify what the program should do when the user clicks a button?
A.Specify the actions to take in a class that implements the ButtonListener interface.
B.Specify the actions to take in a class that implements the EventListener interface.
C.Specify the actions to take in a class that implements the ButtonEvent interface.
D.Specify the actions to take in a class that implements the ActionListener interface.
A.Specify the actions to take in a class that implements the ButtonListener interface.
B.Specify the actions to take in a class that implements the EventListener interface.
C.Specify the actions to take in a class that implements the ButtonEvent interface.
D.Specify the actions to take in a class that implements the ActionListener interface.
Unlock Deck
Unlock for access to all 100 flashcards in this deck.
Unlock Deck
k this deck