Sams Teach Yourself Java in 21 Days (Covering Java 8 and Android)
HOME / FEEDBACK / ORDER THE BOOK / OTHER BOOKS / PREVIOUS DAY / NEXT DAY / THANKS
ROGERS CADENHEAD

Day 12: Responding to User Input

Certification Practice

Each chapter of the book ends with a Certification Practice question that's comparable to what you could expect to be asked on a Java certification test. Here's the answer for chapter 12:

Answer (c) is correct. When no action command has been explicitly set up for an interface component such as a JButton, the getActionCommand() method returns the text label of the component. Calling equals("Yes") on this string returns true when the text of the button that was clicked is "Yes".

Answer (a) is incorrect. Both components that have action listeners are JButton objects, so instanceof will always be true.

Answer (b) is incorrect. Everything is correct up to the point that the text of the component's equals("yes") method is called. The equals() method is case-sensitive, so it always returns false because none of the buttons has the text "yes".

Answer (d) is incorrect because the program will not compile successfully with this line in it. The conditional associated with an if statement must be surrounded by parenthesis marks. Edit

Return to Day 12

HOME / FEEDBACK / ORDER THE BOOK / OTHER BOOKS / PREVIOUS DAY / NEXT DAY / THANKS

Valid HTML 4.01!

Valid CSS!