Sample Quiz2 Answers

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Sample Quiz #2--Answers

CS 151

Sample Quiz #2Answers


1. A(n) _________________ represents a user action, such as clicking a JButton. a) statement b) event c) application d) function ANS: b

2. A _________________ operator has two operands. a) comment b) text c) binary d) None of the above. ANS: c 3. Comments _________________. a) help improve application readability b) are preceded by two forward slashes c) are ignored by the compiler d) All of the above. ANS: d

4. Method _________________ is used to modify the text property of a JTextField. a) changeText b) getText c) setText d) modifyText ANS: c 5. A portion of code that performs a specific task and may return a value is known as a(n) _________________. a) variable b) method c) operand d) identifier ANS: b 6. Java keywords are _________________. a) identifiers b) reserved for use by Java c) case sensitive d) Both b and c. ANS: d 7. Class declarations end with a _________________. a) right brace (}) b) semicolon (;) c) end keyword
ECC

Niko ulevski

Sample Quiz #2--Answers

CS 151

d) class keyword ANS: a

8. Parentheses that are added to an expression simply to make it easier to read are known as _________________ parentheses. a) necessary b) redundant c) embedded d) nested ANS: b 9. The _________________ operator performs division. a) / b) \ c) % d) * ANS: a 10. Every variable has a _________________. a) name b) type c) Both of the above d) Neither of the above ANS: c 11. If an expression contains several multiplication, division and remainder operators, they are performed from _________________. a) right to left b) left to right c) Both of the above d) Neither of the above ANS: b 12. Reading a value from a variable is a _________________ process. a) destructive b) nondestructive c) overwriting d) None of the above ANS: b 13. Pressing a key in a JTextField raises the _________________ event a) textTyped b) valueChanged c) pressedKey d) keyPressed ANS: d 14. The debugger command _________________ sets a breakpoint at an executable line of source code in an application. a) stop
ECC

Niko ulevski

Sample Quiz #2--Answers

CS 151

b) run c) print d) clear ANS: a 15. Variables used to store integer values should be declared with keyword _________________. a) integer b) int c) intVariable d) Int ANS: b 16. The debugger command _________________ allows you to peek into the computer and look at the value of a variable. a) value b) variable c) print d) peek ANS: c 17. A _________________ occurs when an executed statement does not directly follow the previously executed statement in the written application. a) transition b) flow c) logical error d) transfer of control ANS: d 18. A variable or an expression can be examined by the _________________ debugger command. a) print b) get c) display d) examine ANS: a 19. The if statement is called a _________________ statement because it selects or ignores one action (or sequence of actions). a) single-selection b) multiple-selection c) double-selection d) repetition ANS: a 20. In an activity diagram, a rectangle with curved sides represents _________________. a) a complete algorithm b) a comment c) an action d) the termination of the application ANS: c

ECC

Niko ulevski

Sample Quiz #2--Answers

CS 151

21. The body of an if statement that contains multiple statements is placed in _________________. a) () b) [] c) <> d){} ANS: d 22. The _________________ operator assigns to the left operand the result of adding the left and right operands. a) + b) =+ c) += d) + = ANS: c 23.* (Extra CreditOptional) Write a program that asks the user for the length of the sides of a square. Then print the area, perimeter and the length of the diagonal of the square. Define a class Square and a class SquareDriver to test the Square class.

Answers
9 10 11 12 13 14 15 16 17 18 19 20 21 22 B C D C B D A B A C B B D A B C D A A C D C 1 2 3 4 5 6 7 8

ECC

Niko ulevski

You might also like