Page 269 - Introduction to Programming with Java: A Problem Solving Approach
P. 269

                • Unless a method’s return type is void, every path through the method must end with a statement that returns a value of the method’s type.
• A method’s parameter must have the same type as the method call’s argument. What the method gets is a copy of what is in the calling program, so changing a parameter in a method does not change the calling program’s value.
• Use setX and getX methods to modify and retrieve private instance variable values. Include filter- ing in setX methods to protect your program from bad input. Use boolean isX methods to return true or false depending on the value of some condition.
• Optionally improve simulation speed and accuracy by computing the next increment with values deter- mined half way between that increment’s starting and ending points.
Review Questions
§6.2 Object-Oriented Programming Overview
1. A class is an instance of an object. (T / F)
2. How many objects may there be within a single class?
§6.3 First OOP Class
3. A class’s instance variables must be declared outside of all   , and all instance variable declarations
should be located at the .
4. Methods accessible from outside a class are public, but instance variables (even those that an outsider
may need to change or read) are usually private. Why?
Review Questions 235
  Apago PDF Enhancer
§6.4 Driver Class
5. Where does main go—in the driver class or in one of the driven classes?
6. When a program has both driver and driven classes, where should most of the program code reside? 7. How do you retrieve a private instance variable’s value from within a main method?
8. A reference variable holds the   of an object.
§6.5 Calling Object, this Reference
9. An instance method might contain a statement like this.weight = 1.0; but if that method’s class
currently has five instantiated objects, there are five different variables called weight. How can we determine which one is getting the new value?
§6.6 Instance Variables
10. What are the default values for int, double, and boolean for an object’s instance variables? 11. In the Mouse program of Figures 6.4 and 6.5, what is the persistence of gus’s age variable?
§6.8 UML Class Diagrams
12. After a program is written, a UML class diagram provides a brief outline of each class in the program. It
helps other people see what methods are available and what arguments they need. Give some reasons why it might be helpful to have an already created class diagram in front of you while you are implementing the class and writing its methods .
§6.9 Local Variables
13. Assume the main method in Mouse2Driver had started more simply with only Mouse mickey; What
would be the value of mickey immediately after this statement?
§6.10 The return Statement
14. Usually, the use of multiple return statements leads to code that is more understandable. (T / F)



































































   267   268   269   270   271