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

                • To make a program more understandable, you can overload a method name by using the same name again in a different method definition that has a different sequence of parameter types. The combina- tion of method name, number of parameters, and parameter types is called a method’s signature.
• A constructor enables you to initialize instance variables separately for each object. A constructor’s name is the same as its class name, and there is no return value specification.
• For a constructor call to work there must be a matching constructor definition, that is, a definition with the same signature.
• If you define a constructor, the default zero-parameter constructor vanishes.
• Use a constructor to initialize instance constants, which represent permanent attributes of individual
objects.
• To call an overloaded constructor from within a constructor, make the first statement in the constructor
be: this(<constructor-argument(s)>).
• Partition a large problem into a set of simpler problems by using multiple driven classes.
Review Questions
§7.2 Object Creation—A Detailed Analysis
1. The statement Car car;
allocates space in memory for an object. (T / F)
Apago PDF Enhancer
2. What does the new operator do?
§7.3 Assigning a Reference
3. Assigning one reference variable to another copies the right-side object’s instance variables into the left-side
object’s instance variables. (T / F)
4. What is a memory leak?
§7.4 Testing Objects for Equality
5. Consider this code fragment:
boolean same;
Car carX = new Car();
Car carY = carX;
same = (carX == carY);
What is the final value of same?
6. What is the return type of an equals method?
7. By convention, we use the name equals for methods that perform a certain kind of evaluation. What is
the difference between the evaluation performed by an equals method and the == operator?
§7.5 Passing References as Arguments
8. When you pass a reference to a method, you enable the method to modify the referenced object. (T / F)
§7.6 Method-Call Chaining
9. What two things must be included in a method definition so that it may be called as part of a method- call-chaining statement?
Review Questions 285
 
































































   317   318   319   320   321