Big Java Early Objects 5th Edition Horstmann Test Bank instant download
Big Java Early Objects 5th Edition Horstmann Test Bank instant download
https://testbankdeal.com/product/big-java-early-objects-5th-
edition-horstmann-test-bank/
https://testbankdeal.com/product/big-java-early-objects-5th-edition-
horstmann-solutions-manual/
testbankdeal.com
https://testbankdeal.com/product/big-java-late-objects-1st-edition-
horstmann-solutions-manual/
testbankdeal.com
https://testbankdeal.com/product/java-how-to-program-early-
objects-11th-edition-deitel-test-bank/
testbankdeal.com
https://testbankdeal.com/product/operations-management-processes-and-
supply-chains-11th-edition-krajewski-solutions-manual/
testbankdeal.com
Contemporary Logistics 12th Edition Murphy Solutions
Manual
https://testbankdeal.com/product/contemporary-logistics-12th-edition-
murphy-solutions-manual/
testbankdeal.com
https://testbankdeal.com/product/introduction-to-human-anatomy-and-
physiology-4th-edition-solomon-test-bank/
testbankdeal.com
https://testbankdeal.com/product/survey-of-econ-1st-edition-sexton-
test-bank/
testbankdeal.com
https://testbankdeal.com/product/fitness-5th-edition-mazzeo-solutions-
manual/
testbankdeal.com
https://testbankdeal.com/product/statistics-for-criminology-and-
criminal-justice-4th-edition-bachman-test-bank/
testbankdeal.com
Educational Psychology Developing Learners 7th Edition
Ormrod Test Bank
https://testbankdeal.com/product/educational-psychology-developing-
learners-7th-edition-ormrod-test-bank/
testbankdeal.com
Chapter 10: Interfaces
Test Bank
Multiple Choice
Answer: b
Answer: d
Answer: b
Answer: a
Answer: b
Answer: d
Answer: d
Answer: c
Answer: a
Answer: c
Answer: a
12. Suppose you are writing an interface called Resizable, which includes one void
method called resize.
Which of the following can be used to complete the interface declaration correctly?
Answer: c
_____________________________
{
// code to encrypt the text using encryption key goes here
}
}
Which of the following method headers should be used to complete the SecretText
class?
Answer: b
void changeSize();
}
Answer: a
The compiler complains that the getMeasure method has a weaker access level than the
Measurable interface. Why?
a) 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.
b) 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.
c) The variable onHandCount was not declared with public access.
d) The getMeasure method was declared as private in the Measurable interface.
Answer: b
17. 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 is in the same package as
the class.
b) You can convert from a class type to any interface type that the class implements.
c) You can convert from a class type to any interface type that the class defines.
d) You cannot convert from a class type to any interface type.
Answer: b
a)
Coin dime = new Coin(0.1, "dime");
Measurable x = dime;
b)
Coin dime = new Coin(0.1, "dime");
Dataset x = dime;
c)
Coin dime = new Coin(0.1, "dime");
DataSet x == (Measureable)dime;
d)
Coin dime = new Coin(0.1, "dime");
BankAccount x = dime;
Answer: a
19. Which of the following statements about converting between types is true?
a) When you cast number types, you take a risk that an exception will occur.
b) When you cast number types, you will not lose information.
c) When you cast object types, you take a risk of losing information.
d) When you cast object types, you take a risk that an exception will occur.
Answer: d
a) You can define an interface variable that refers to an object of any class in the same
package.
b) You cannot define a variable whose type is an interface.
c) You can instantiate an object from an interface class.
d) You can define an interface variable that refers to an object only if the object belongs
to a class that implements the interface.
Answer: d
21. You have created a class named Motor that implements an interface named
Measurable. You have declared a variable of type Measureable named
motorTemperature. Which of the following statements is true?
Answer: b
22. ____ occurs when a single class has several methods with the same name but
different parameter types.
a) Casting
b) Polymorphism
c) Overloading
d) Instantiation
Answer: c
a) overloading
b) callback
c) early binding
d) polymorphism
Answer: d
24. If you have multiple classes in your program that have implemented the same
interface in different ways, how is the correct method executed?
a) The Java virtual machine must locate the correct method by looking at the class of the
actual object.
b) The compiler must determine which method implementation to use.
c) The method must be qualified with the class name to determine the correct method.
d) You cannot have multiple classes in the same program with different implementations
of the same interface.
Answer: a
What method invocation can be used to complete the code segment below?
a) increaseSize()
b) decreaseSize()
c) display()
d) display(5)
Answer: c
26. Which of the following can potentially be changed when implementing an interface?
Answer: c
28. The method below is designed to print the smaller of two values received as
arguments. Select the correct expression to complete the method.
Answer: d
a) A callback can allow you to implement a new method for a class that is not under your
control.
b) A callback can be implemented using an interface.
c) A callback is a mechanism for specifying code to be executed later.
d) A callback method declared in an interface must specify the class of objects that it will
manipulate.
Answer: d
Answer: b
31. You wish to implement a callback method for an object created from a system class
that you cannot change. What approach does the textbook recommend to accomplish
this?
Answer: d
Answer: c
What parameter declaration can be used to complete the callback measure method?
a) Object anObject
b) String anObject
c) Object aString
d) String aString
Answer: a
Title: Identify correct parameter declaration to complete callback method
Difficulty: Easy
Section Reference 1: 10.4 Using Interfaces for Callbacks
34. 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?
Answer: b
Title: Identify correct declaration using inner class to complete main method
Difficulty: Medium
Section Reference 1: 10.5 Inner Classes
a) An inner class can only be defined within a specific method of its enclosing class.
b) An inner class can only be defined outside of any method within its enclosing class.
c) An inner class must implement an interface.
d) An inner class may be anonymous.
Answer: d
Answer: d
Answer: b
Answer: d
a) An anonymous class.
b) An anonymous object.
c) An abstract object.
d) An abstract class.
Answer: b
a) A mock class does not provide an implementation of the services of the actual class.
b) A mock class provides a complete implementation of the services of the actual class.
c) A mock class provides a simplified implementation of the services of the actual class.
d) A mock class must be an interface.
Answer: c
41. What role does an interface play when using a mock class?
a) The mock class should be an interface that will be implemented by the real class.
b) The real class should be an interface that will be implemented by the mock class.
c) Interfaces are not involved when using mock classes.
d) 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.
Answer: d
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 respond to notifications of all types of events that are sent to it by
the Java window manager.
D) Your program must override the default methods to handle events.
Answer: a
Which of the following method headers should be used to complete the ClickListener
class?
Answer: a
44. ____ are generated when the user presses a key, clicks a button, or selects a menu
item.
a) Listeners
b) Interfaces.
c) Events.
d) Errors.
Answer: c
45. A/an ____ belongs to a class whose methods describe the actions to be taken when a
user clicks a user-interface graphical object.
a) Event listener
b) Event source
c) Action listener
d) Action method
Answer: a
a) A JButton object.
b) An event listener.
c) An inner class.
d) An event adapter.
Answer: a
47. To respond to a button event, a listener must supply instructions for the ____ method
of the ActionListener interface.
a) actionEvent.
b) actionPerformed
c) eventAction
d) eventResponse
Answer: b
48. To associate an event listener with a JButton component, you must use the ___
method of the JButton class.
a) addEventListener.
b) addActionListener.
c) addButtonListener.
d) addListener
Answer: b
49. The methods of a/an ____ describe the actions to be taken when an event occurs.
a) event source
b) event listener
c) event interface
d) action source
Answer: b
50. When an event occurs, the event source notifies all ____.
a) components
b) panels
c) interfaces
d) event listeners
Answer: d
Section 10.7 Event Handling
Title: When an event occurs, the event source notifies all ____.
Difficulty: Easy
a) text area
b) table
c) panel
d) rectangle
Answer: c
a)
public interface AccountListener()
{
void actionPerformed(AccountEvent event);
}
b)
public interface AccountListener()
{
void actionPerformed(AccountEvent);
}
c)
public interface AccountListener
{
void actionPerformed(AccountEvent event);
}
d)
public abstract AccountListener
{
void actionPerformed(AccountEvent event);
}
Answer: c
Answer: a
a) frame.add(panel);
b) frame.add(JPanel panel);
c) frame.addComponent(panel);
d) frame.addComponent(JPanel panel);
Answer: a
Section 10.8 Building Applications with Buttons Title: How to add a panel to a frame.
Difficulty: Easy
/**
An action listener that prints.
*/
public class ClickListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
System.out.println("I was clicked.");
}
}
Which of the following statements will complete this code?
a) java.swing.event.ActionEvent;.
b) javax.swing.event.ActionEvent;
c) javax.awt.event.ActionEvent;
d) java.awt.event.ActionEvent;
Answer: d
56. Event listeners are often installed as ____ classes so that they can have access to the
surrounding fields, methods, and final variables.
a) Inner
b) Interface
c) Abstract
d) Helper
Answer: a
a) An inner class may not be declared within a method of the enclosing scope.
b) An inner class may only be declared within a method of the enclosing scope.
c) An inner class can access variables from the enclosing scope only if they are passed as
constructor or method parameters.
d) The methods of an inner class can access variables declared in the enclosing scope.
Answer: d
Answer: b
59. An inner class can access local variables from the enclosing scope only if they are
declared as ____.
a) private
b) public
c) static
d) final
Answer: b
Answer: d
Section 10.8 Building Applications with ButtonsTitle: Which statement creates a button?
Difficulty: Easy
61. To build a user interface that contains graphical components, the components ____.
a) Must be added directly to a frame component.
b) Must each be added to a separate panel.
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.
Answer: c
Section 10.8 Building Applications with ButtonsTitle: To build a user interface, the
graphical components ____.
Difficulty: Easy
62. 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 ButtonEvent interface .
c) Specify the actions to take in a class that implements the ActionListener interface.
d) Specify the actions to take in a class that implements the EventListener interface.
Answer: c
Section 10.8 Building Applications with ButtonsTitle: How to specify action for a
button?
Difficulty: Medium
63. A(n) ____ has an instance method addActionListener() for specifying which
object is responsible for implementing the action associated with the object.
a) JFrame
b) JSlider
c) JButton
d) JLabel
Answer: c
Section 10.8 Building Applications with ButtonsTitle: How to specify action for a button.
Difficulty: Medium
Answer: c
Section 10.8 Building Applications with ButtonsTitle: What is wrong with this listener
code?
Difficulty: Medium
Which of the local variables can be accessed within the actionPerformed method?
Answer: c
Section 10.8 Building Applications with ButtonsTitle: Which local variables can be
accessed?
Difficulty: Medium
66. Consider the following code snippet which is supposed to show the total order
amount when the button is clicked:
public static void main(String[] args)
{
final Order myOrder = new Order();
JButton button = new JButton("Calculate");
final JLabel label = new JLabel("Total amount due");
. . .
class MyListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
label.setText("Total amount due " + myOrder.getAmountDue());
}
}
ActionListener listener = new MyListener();
}
Answer: b
a) setPreferredDimensions.
b) setInitialDimensions.
c) setPreferredSize.
d) setInitialSize.
Answer: c
68) Assuming that the ClickListener class implements the ActionListener interface,
what statement should be used to complete the following code segment?
a) myPanel.addActionListener(listener);
b) myButton.addActionListener(listener);
c) myPanel.addActionListener(myButton);
d) myButton.addActionListener(ClickListener);
Answer: b
Title: Identify correct statement to add event listener object to a graphical object
Difficulty: Medium
Section Reference 1: 10.8 Building Applications with Buttons
69) Assume that the TimerListener class implements the ActionListener interface. If
the actionPerformed method in TimerListener needs to be executed every second,
what statement should be used to complete the following code segment?
Answer: d
a) java.awt.
b) javax.awt.
c) java.swing.
d) javax.swing.
Answer: d
71. When you use a timer, you need to define a class that implements the ____ interface.
a) TimerListener
b) TimerActionListener
c) ActionListener
d) StartTimerListener
Answer: c
72. The ____ class in the javax.swing package generates a sequence of events, spaced
apart at even time intervals.
a) TimeClock
b) Timer
c) Clock
d) StopWatch
Answer: b
Section 10.9 Processing Timer Events
Title: Which class generates events at even time intervals?
Difficulty: Easy
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
Answer: d
public RectangleComponent()
{
// The rectangle that the paint method draws
box = new Rectangle(BOX_X, BOX_Y,
BOX_WIDTH, BOX_HEIGHT);
}
g2.draw(box);
}
a) repaint();
b) g2.draw(box);
c) box.setLocation(x, y);
d) private Rectangle box;
Answer: a
Answer: b
76. You have a class which extends the JComponent class. In this class you have created
a painted graphical object. Your code will change the data in the graphical object. What
additional code is needed to ensure that the graphical object will be updated with the
changed data?
Answer: b
77. The ____ method should be called whenever you modify the shapes that the
paintComponent method draws.
a) draw
b) paint
c) paintComponent
d) repaint
Answer: d
78. If the user presses and releases a mouse button in quick succession, which methods
of the MouseListener interface are called?
Answer: b
Section 10.10 Mouse Events
Title: Which MouseListener interface methods are called?
Difficulty: Medium
a) 0
b) 1
c) 3
d) at least 5
Answer: d
a) addListener
b) addMouseListener
c) addActionListener
d) addMouseActionListener
Answer: b
a) action listener
b) event listener
c) mouse listener
d) component listener
Answer: c
82. You wish to detect when the mouse is moved into a graphical component. Which
methods of the MouseListener interface will provide this information?
a) mouseMoved
b) mouseEntered
c) mouseOver
d) mouseIncoming
Answer: b
a) The mouseClicked method cannot access the x and y coordinates of the mouse.
b) repaint() method was not called.
c) The class has implemented the wrong interface.
d) There is nothing wrong with this code.
Answer: c
Which of the following statements should be in the indicated position to print out where
the mouse was pressed?
a) x = event.getXposition(); y = event.getYposition();
b) x = (MouseEvent) getX(); y = (MouseEvent) getY();
c) x = event.printX(); y = event.printY();
d) x = event.getX(); y = event.getY();
Answer: d
Answer: a
Sieltä meni Petteri jälleen huoneeseen 427. Nell oli arvellut ettei
Nelse Ackerman tule menettämään minuuttiakaan seuraavana
aamuna; ja niin kävikin. Petteri löysi kirjeen pöydältä, jossa
sanottiin: "Odota minua, haluan tavata sinut."
"Tiedän — luonnollisesti."
"Voit ehkä luulla että tässä nyt on sinulla tilaisuus hypätä meidän
selkäämme ja kiivetä korkeammalle meitä, mutta älä unohda, Petteri
Gudge, että koneisto on meidän hallussamme, ja viime tingassa se
on aina koneisto, joka voittaa. Olemme lyöneet mäsäksi montakin
miestä, jotka ovat yrittäneet metkuilla kanssamme, ja niin teemme
sinullekin. Vanha Nelse tulee kiskomaan sinusta irti mitä tietoja vain
halunneekin; epäilemättä tulee hän tarjoomaan sinulle hyvän hinnan
— mutta ennen pitkää olet pelisi pelannut hänen kanssaan ja palaat
tänne, mutta annan sinulle varotuksen: kautta luojan, jos vain pelaat
saastaista peliä kassamme, niin Guffey heittää sinut rotkoon
kuukauden tai parin perästä, ja sieltä sinut kannetaan ulos
paareilla!"
"Kyllä."
"Sanottiin."
"Kyllä."
"Gudge", sanoi taas hetken kuluttua tuo vanha mies. "En halua
kuolla; en tahdo että minut tapetaan."
"Ettepä tietenkään", sanoi Petteri. Sen hän selvästi käsitti, ettei Mr.
Ackerman halunnut tulla tapetuksi. Mutta Mr. Ackerman näytti olevan
sitä mieltä, että tämä seikka täytyy saada aivan selväksi Petterille; ja
keskustelun kestäessä hän toisti tämän useita kertoja, ja joka
kerralla sanoi hän sen samalla hartaalla vakavuudella kuin olisi se
aivan uusi, hyvin outo ja ihmeellinen ajatus. "En halua tulla
tapetuksi, Gudge; kuuletteko, en halua että nuo miehet saavat minut
käsiinsä. Ei, ei; meidän täytyy tehdä heidän aikeensa tyhjäksi,
meidän täytyy ryhtyä varokeinoihin — meidän täytyy ottaa kaikki
seikat huomioon, ryhtyä kaikkiin mahdollisiin varokeinoihin."
"Et saa potkua, kyllä siitä pidän huolen. Jollei muu auta, niin
palkkaan teidät itse persoonallisesti."
"Kuka se on?"
"Se oli ainoa minkä kuulin", sanoi Petteri. "En tiennyt mitä se
merkitsee. Mutta kun kuulin piirustuksesta, jonka Mac oli tehnyt
teidän talostanne, niin ajattelin: Jeesus, se varmaankin oli Mr.
Ackerman, jonka hän aikoi ampua!"
LIII:
Vähitellen saapuivat he kysymykseen käytännöllisistä
toimenpiteistä, ja Petterillä oli valmiina esityksiä. Ensiksikin, Mr.
Ackerman ei saa antaa vihiä poliisilaitokselle eikä Guffeyn
salapoliisilaitokselle siitä, että hän on tyytymätön niiden toimintaan.
Hänen tulee vain silloin tällöin laittaa niin, että saa puhutella
kahdenkesken Petteriä, ja Petteri tulee persoonallisesti ryhtymään
toimenpiteisiin taatakseen Mr. Ackermanille sen turvallisuuden,
minkä hänen tärkeytensä koko kaupungin hyvinvoinnille vaati.
Ensimäinen tehtävä oli saada selville, oliko todellakin Ackermanin
kotona petturi, ja sitä varten tarvittaisiin vakooja, ensiluokan
salapoliisi, jolla olisi jonkunlainen toimi talossa. Ainoa pula oli se,
että löytyi niin harvoja salapoliiseja, joihin voi luottaa; ne olivat
melkein kaikki lurjuksia, ja jolleivät ne olleet lurjuksia, oli se siksi,
ettei niillä ollut kylliksi älliä lurjuksiksi — ne olivat hölmöjä ja punikit
voivat nähdä ne läpi kuin lasin.
"Mutta kuulkaa", sanoi Petteri, "mitä olen ajatellut. Minulla on
vaimo, joka on ihmeen etevä, ja juuri nyt, kun puhelimme tästä,
pälkähti päähäni että jos vain voisin saada Edythen tänne
muutamaksi päiväksi, niin voisimme päästä selville kaikista ihmisistä
tässä talossa, sukulaisistanne niin hyvin kuin palvelijoistannekin."
"Ei ole", sanoi Petteri. "Enkä tiedä olisiko hän halukas tekemään
tämän vai ei, sillä hän ei halua että minulla olisi mitään tekemistä
noiden punikkien kanssa, ja hän on pyydellyt minua jättämään koko
tämän homman, ja minä olen lupaillutkin jo vähän. Mutta jos kerron
hänelle teidän pulastanne, niin ehkä saisin hänet myöntymään —
hänellä on hyvä sydän."
Hän kertoi Nellille kaiken mikä tapahtunut oli ja sanoi että hänen
on mentävä tapaamaan Mr. Ackermanin veljentytärtä. "Mitä hän
sinulle antoi?" uteli Nell heti, ja kun Petteri näytti noita kahta seteliä,
huudahti Nell: "Hyvä jumala! millainen vanha kitupiikki!"
"Minä pidän sen tallella sinulle", sanoi Nell, "ja jonakin päivänä,
kun tarvitset, tulet olemaan iloinen että sinulla on mistä ottaa. Sinä
et ole koskaan säästänyt mitään itse; sitä eivät tee muut kuin
naiset."
Petteri vastasi: "Hän vain halusi ottaa selvää siitä, että saako hän
tietoonsa kaiken mikä on tärkeää, ja hän vaati minua lupaamaan
että hän tulee saamaan tietoonsa joka seikan salaliitosta häntä
vastaan, mikä vain tulee esille; ja minä lupasin että ilmoitamme
hänelle heti kaiken."
"Ei, ja luulen että jos hän haluaa puhutella minua, antaa hän
teidän tietää siitä, niinkuin ennenkin."
Pikku Ada Ruth sanoi että tuo on hulluutta; mutta parempi olisi
hankkia lippuja ja kulkea edestakasin vankilan edessä, vastalauseeksi
siitä, että rääkätään niin hirveästi miehiä, vaikka heitä ei ole tuomittu
edes syyllisiksi. Poliisit luonnollisesti olisivat heti heidän niskassaan,
väkijoukko hyökkäisi heidän kimppuunsa ja ehkä repisi heidät
kappaleiksi, mutta vähät siitä, jotakin on tehtävä. Donald Gordon
vastasi, että tästä ei olisi mitään muuta hyötyä kuin että heidän olisi
sitten enää mahdoton pitää yllä agitatsionia. Heidän täytyy koettaa
saada aikaan lakko. Heidän täytyy lähettää sähkösanomia radikalisille
sanomalehdille, koota rahaa ja kutsua kokoon joukkokokous kolmen
päivän päähän. Myöskin olisi koetettava vaikuttaa kaikkiin
työväenunioihin että nämä tekisivät yleislakon.