Chapter 2 review questions and examples Which of the following is

advertisement
Chapter 2 review questions and examples
1. Which of the following is true in object programming?
C. all applications are programs
2. In object oriented programming, a main method ________________________
B. is the method that executes first.
3. In object oriented programming, the identifier for a class, method or variable ______________
D. None of the above (it uses upper camel casing)
4. A set of parentheses always follows a _______________
A. Method name
5. Which of the following is a literal numeric constant?
A. 12
6. What does a declaration provide for a variable?
C. Both of the above (name AND data type)
7. A variables data type describes all of the following except _________________
D. What part of the program in which the variable can be used.
8. In many languages, the value stored in an uninitialized variable is __________________
A. Garbage
9. The value of “house” is a ________________________
D. string constant.
10. If size has been declared to be a string variable, which of the following is legal?
D. two of the above (B. size = “six” and C. size = “6”)
11. Which of the following is true if a declaration has been made as follows: num count ?
B. count is a numeric variable.
12. which of the following statements id true if a declaration has been made as follows:
num count = 9 ?
B. count is a numeric variable.
13. the assignment operator _____________________________
A. is a binary operator
14. Which of the following is true about the arithmetic prescedence?
C. Division has higher precedence than subtraction.
15. which of the following statements evaluate to 10?
B. 5+20/4
16. What is the value of the expression 8 – 4 * 6 / 4
A. 2
17. program comments are _____________________
D. None of the above.
18. which of the following is valid advice for naming variables?
C. to make names easier to read, separate long phrases by using underscores or capitalization for
each new word.
19. a message that asks for user input is a ______________
B. Prompt.
20. Which of the following is a list of the three structures?
C. Sequence, selection and loop.
Exercises
1. Using this books conventions identify each of the following as a class, method or variable name.
a. calculateInsurancePremium ()
b. premium
c. premiumValue
d. paymentAmount
e. InsuranceRequirements
f. deductPremium
g. clientage
- method
- variable
- variable
- variable
- class
- method
- variable
2. Explain why each of the following names does or does not seem like a good variable.
a. p
what it is for.
-this one is bad, it does not clearly show
b. product
- this one is ok, in an application this
variable might be to vauge to allow the application to be self-documenting.
c. productNumber
- this one is good. It might be necessary
to define the type of product number either in comment form or a different variable name.
d. product number
words in a variable are not allowed.
- this one is wrong, spaces between
e. pdtnmbr
- this one is bad, unless the
documentation is extremely clear anyone trying to debug or reverse engineer this would have
some deciphering to do.
f. sevenDigitProductNumberAssignedByManufacturer
- this one is far too long
g. productionFor2014
h.
-
Download