Computer Programming CH 13

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which of the following is true? a. A precondition must be true when a method is invoked. b. A postcondition must be true when a method successfully returns to its caller. c. Both of the above. d. Neither of the above

a. A precondition must be true when a method is invoked.

When the user presses Enter in a JPasswordField, the GUI component generates an _______, which is processed by an object that implements the interface ________ . a. ActionEvent, ActionListener. b. ActionEvent, ActionEventListener. c. TextEvent, TextListener. d. TextEvent, TextEventListener.

a. ActionEvent, ActionListener.

Which layout manager is the default for JFrame? a. FlowLayout. b. BorderLayout. c. GridLayout. d. None of the above

a. FlowLayout.

Which of the following statements regarding the throw point of an exception is false? a. It specifies the point at which the exception must be handled. b. It is the initial point at which the exception occurs. c. It is specified as the top row of the method-call stack at the time the exception occurred. d. All of the above statements are true

a. It specifies the point at which the exception must be handled.

Which of the following is not a GUI component (control or widget)? a. String. b. Button. c. Menu. d. Combo box

a. String.

Which of the following statements is true? a. The throw statement is used to throw an exception. b. The throw statement is used to specify that a method will throw an exception. c. The throw statement is used to access an exception parameter. d. All of the above.

a. The throw statement is used to throw an exception

In Java, after an exception is handled, control resumes . This is known as the model of exception handling. a. after the last catch block (or the finally block, if there is one), termination b. after the last catch block (or the finally block, if there is one), resumption c. just after the throw point, termination d. just after the throw point, resumption

a. after the last catch block (or the finally block, if there is one), termination

The BorderLayout layout manager: a. divides an area into five regions: NORTH, SOUTH, EAST, WEST and CENTER. b. divides an area into five regions: UP, DOWN, LEFT, RIGHT and MIDDLE. c. orders components vertically. d. order components horizontally.

a. divides an area into five regions: NORTH, SOUTH, EAST, WEST and CENTER.

Which method determines if a JCheckBox is selected? a. isSelected. b. getSelected. c. selected. d. None of the above.

a. isSelected.

Exceptions can be thrown by: a. the Java Virtual Machine. b. code in a try block. c. calls from a try block to other methods. d. All of the above.

a. the Java Virtual Machine.

Method getSelectedIndex of class JComboBox returns: a. the index of the selected item in the JComboBox. b. the selected item in the JComboBox, as a String. c. the index of the previously selected item. d. None of the above.

a. the index of the selected item in the JComboBox.

Which region is used by default when a Component is added to a BorderLayout? a. NORTH. b. CENTER. c. WEST. d. LEFT.

b. CENTER.

Which of the following statements is false? a. Exception handling enables programmers to write robust and fault-tolerant programs. b. Exception handling can catch but not resolve exceptions. c. Exception handling can resolve exceptions. d. All of the above are true.

b. Exception handling can catch but not resolve exceptions.

Which of the following exceptions is a checked exception? a. ArithmeticException. b. IOException. c. RuntimeException. d. InputMismatchException.

b. IOException.

_______________ provides the basic attributes and behaviors of a window—a title bar at the top of the window, and buttons to minimize, maximize and close the window. a. JLabel. b. JFrame. c. JSwing. d. JWindowControl

b. JFrame.

Which of the following statements is false? a. All exceptions must derive from the class Throwable. b. The class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream. c. The class Throwable provides the method getMessage that returns the descriptive string stored in an exception. d. The string returned from class Throwable's getMessage method contains the name of the exception's class.

b. The class Throwable provides the method getStackTrace that outputs the stack trace to the standard error stream.

In the catch block below, what is arithmeticException? catch ( ArithmeticException arithmeticException ) { System.err.printf( arithmeticException ); } // end catch a. The type of the exception being caught. b. The name of catch block's exception parameter. c. A finally block. d. An exception handler

b. The name of catch block's exception parameter.

Which expression returns the location of a file as a URL? a. getURL( "file.txt" ). b. getResource( "file.txt" ). c. findResource( "file.txt" ). d. getClass( "file.txt" )

b. getResource( "file.txt" ).

Together, the appearance and the way in which the user interacts with the application are known as that application's . a. abstract window toolkit. b. look-and-feel. c. swing factor. d. All of the above.

b. look-and-feel.

Which of the following statements makes the text in a JTextField uneditable? a. textField.setEditable( true ); b. textField.setEditable( false ); c. textField.setUneditable( true ); d. textField.setUneditable( false );

b. textField.setEditable( false );

If the catch-or-declare requirement for a checked exception is not satisfied: a. the compiler will issue an error message indicating that the exception must be caught. b. the compiler will issue an error message indicating that the exception must be caught or declared. c. a stack trace will be displayed indicating the exception that has occurred and where it occurred. d. a stack trace will be displayed, along with a message indicating that the exception must be caught.

b. the compiler will issue an error message indicating that the exception must be caught or declared.

When an exception occurs it is said to have been: a. caught. b. thrown. c. declared. d. handled

b. thrown.

The method setRolloverIcon is used to: a. Handle a key event. b. Change the button text. c. Change the button icon. d. All of the above.

c. Change the button icon.

Which JFrame constant indicates that the program should terminate when the window is closed by the user? a. TERMINATE_ON_CLOSE. b. IMMEDIATELY_CLOSE. c. EXIT_ON_CLOSE. d. All of the above.

c. EXIT_ON_CLOSE.

The JOptionPane constant used to display an icon prompting the user for input is: a. JOptionPane.ERROR_MESSAGE. b. JOptionPane.INFORMATION_MESSAGE. c. JOptionPane.QUESTION_MESSAGE. d. JOptionPane.WARNING_MESSAGE.

c. JOptionPane.QUESTION_MESSAGE.

Which of the following statements is true? a. Using existing exceptions makes the program less robust. b. Always create your own exception classes. c. Like any other class, an exception class can contain fields and methods. d. The new exception class should extend RuntimeException if the program should be required to handle the exception

c. Like any other class, an exception class can contain fields and methods.

Consider the list below: January February March April May June July August September October November December What type of JList selection mode would allow the user to select March, June and July in one step? a. SINGLE_SELECTION. b. SINGLE_INTERVAL_SELECTION. c. MULTIPLE_INTERVAL_SELECTION. d. All of the above.

c. MULTIPLE_INTERVAL_SELECTION.

Which component contains menus? a. Menu button. b. Title bar. c. Menu bar. d. Combo box.

c. Menu bar.

Which of the following statements is false? a. A finally block is placed after the last catch block. b. A finally block typically releases resources acquired in the corresponding try block. c. The finally block and try block can appear in any order. d. A finally block is optional.

c. The finally block and try block can appear in any order.

What is the difference between a try block and a try statement? a. There is no difference; the terms can be used interchangeably. b. A try statement refers to the block of code following the keyword try, while the try block refers to the try keyword and the block of code following this keyword. c. The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finally clauses together form a try statement. d. The try statement refers to the keyword try followed by a block of code. The try statement and its corresponding catch and/or finally clauses together form a try block.

c. The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finally clauses together form a try statement.

Which of the following does not generate GUI events? a. Typing in a text field. b. Selecting an item from a menu. c. Viewing the text in a label. d. Moving the mouse

c. Viewing the text in a label.

In what cases are adapter classes useful? a. When an adapter GUI control is clicked. b.When every method in the event-listener interface is to use the same functionality. c. When it is not desirable to declare every method in the event-listener interface. d.None of the above.

c. When it is not desirable to declare every method in the event-listener interface.

Which of the following statements about the try-with-resources statement is false? a. The try-with-resources statement simplifies writing code in which you obtain a resource, use it in a try block and release the resource in a corresponding finally block. b. You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then the statement implicitly calls the resource's close method at the end of the try block. c. You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then you explicitly call the resource's close method at the end of the try block. d. Each resource must be an object of a class that implements the AutoCloseable interface—such a class has a close method.

c. You allocate the resource in the parentheses following the try keyword and use the resource in the try block; then you explicitly call the resource's close method at the end of the try block.

The class GridLayout constructs _________ to hold components. a. a horizontal grid with one row. b. a vertical grid with one column. c. a grid with multiple rows and columns. d. a square grid with the same number of rows as columns

c. a grid with multiple rows and columns.

Chained exceptions are useful for finding out about: a. exceptions thrown using the chained keyword. b. checked exceptions only. c. an original exception that was caught before the current exception was thrown. d. the current exception's chain of superclasses.

c. an original exception that was caught before the current exception was thrown.

Java SE 7's multi-catch enables you to catch multiple exception types in a single catch handler and perform the same task for each type of exception. The syntax for a multi-catch is: a. catch ( Type1 or Type2 or Type3 e ) b. catch ( Type1 e1 | Type2 e2 | Type3 e3 ) c. catch ( Type1 | Type2 | Type3 e ) d. catch ( Type1 e1 or Type2 e2 or Type3 e )

c. catch ( Type1 | Type2 | Type3 e )

All exception classes inherit, either directly or indirectly, from: a. class Error. b. class RuntimeException. c. class Throwable. d. None of the above.

c. class Throwable.

An uncaught exception: a. is a possible exception that never actually occurs during the execution of the program. b. is an exception that occurs for which the matching catch clause is empty. c. is an exception that occurs for which there are no matching catch clauses. d. is another term for a thrown exception.

c. is an exception that occurs for which there are no matching catch clauses.

Which of the following is not a KeyListener method? a. keyPressed. b. keyReleased. c. keyClicked. d. keyTyped.

c. keyClicked.

Which of the following is a MouseMotionListener method? a. mousePressed. b. mouseExited. c. mouseDragged. d. mouseClicked

c. mouseDragged.

Method can be used to set the layout manager of a container. a. setManager. b. setLayout. c. setLayoutManager. d. setGUILayout.

c. setLayoutManager.

The throws clause of a method: a. specifies the exceptions a method catches. b. specifies the exceptions thrown by the calling method. c. specifies the exceptions a method throws. d. specifies the exceptions a method throws and catches

c. specifies the exceptions a method throws.

To catch an exception, the code that might throw the exception must be enclosed in a a. throws block. b. catch block. c. try block. d. finally block.

c. try block.

Which of the following are types of assertions? a. Preconditions. b. Postconditions. c. Conditions in control statements. d. (a), (b) and (c). e. (a) and (b).

d. (a), (b) and (c).

Which of the following errors is synchronous? a. Divide by zero. b. Arithmetic overflow. c. Unsuccessful memory allocation. d. All of the above.

d. All of the above

When an unchecked exception occurs in a method but is not caught: a. the method-call stack is "unwound." b. the method terminates. c. all local variables in that method go out of scope. d. All of the above.

d. All of the above.

The logical relationship between radio buttons is maintained by objects of what class? a. MutualExclusionGroup. b. RadioButtonGroup. c. Group. d. ButtonGroup.

d. ButtonGroup.

Which of the following is not included in an exception's stack trace? a. A descriptive message for the exception. b. The method-call stack at the time the exception occurred. c. The name of the exception. d. Instructions on handling the exception

d. Instructions on handling the exception

Which of the following statements is true? a. The code in a finally block is executed only if an exception occurs. b. The code in a finally block is executed only if an exception does not occur. c. The code in a finally block is executed only if there are no catch blocks. d. None of the above are true.

d. None of the above are true.

Which of the following statements about try blocks is true? a. The try block must be followed by at least one catch block. b. The try block must be followed by a finally block. c. The try block should contain statements that may process an exception. d. The try block should contain statements that may throw an exception

d. The try block should contain statements that may throw an exception

A JLabel can be attached to a JFrame using method: a. attach. b. contain. c. append. d. add.

d. add.

After a finally block has finished executing (and there are no exceptions to be handled: a. control proceeds to the first statement after the finally block. b. control returns to the throw point. c. the application exits. d. control proceeds to the first statement after the last catch block.

d. control proceeds to the first statement after the last catch block.

The GUI event with which the user interacts is the _____. a. event effector. b. event container. c. event raiser. d. event source.

d. event source.

Which method sets the text that's displayed when the user hovers over a JLabel? a. setHover. b. setHoverText. c. setToolTip. d. setToolTipText.

d. setToolTipText.

Which of the following is the method used to display a dialog box to gather input? a. showMessageDialog. b. getInput. c. inputDialog. d. showInputDialog.

d. showInputDialog.


Set pelajaran terkait

BIO 1114 - Ch 4 - The Energy of Life

View Set

Patho Exam 2 Musculoskeletal System

View Set

Chapter 1 Video Lecture Assignment

View Set

Grandes Maestros Examen I Velázquez

View Set

Patho Chapter 13: disorders of RBCs

View Set

Emission Control System Fundamentals

View Set

Cell Biology Chapter 6 True False

View Set

Pharmacology and Medication Management - ML8

View Set

AP Psychology - First semester Final

View Set