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

                public void display(int x)
{
}
x += 10;
System.out.println(x);
} // end SillyClass class
Review Question Solutions
1. False. It just allocates memory for a reference variable.
2. The new operator allocates memory for an object and returns the address of where that object is stored in
memory.
3. False. Assigning a reference variable to another reference variable causes the address in the right side’s reference variable to be put into the left side’s reference variable. And that makes both reference variables refer to the same object.
4. A memory leak is when an inaccessible object is allowed to persist and use up space in a computer’s memory.
5. The final value of same is true.
6. The return type of an equals method is boolean.
Review Questions Solutions 293
 7. The == operator compares the values of two variables of the same type. If the variables are reference Apago PDF Enhancer
variables, == compares their addresses to see if they refer to the same object. An equals method typically compares the values of all the instance variables in the object referred to by its parameter with the values of corresponding instance variables in the object that called it. The equals method returns true only if all corresponding instance variables have the same values.
8. True. The reference gives the method access to the reference’s object.
9. For a method to be called as part of a method-call-chaining statement, include these things:
• Withinthemethodbody,specifyreturn<reference-variable>;
• Withinthemethodheading,specifythereferencevariable’sassociatedclassasthereturntype.
10. If you have two or more methods with the same name in the same class, they’re called overloaded methods.
11. True.
12. A constructor does not have a return type and it does not use a return statement, but when you call a constructor, new returns a reference to the constructed object.
13. True.
14. False. Standard coding conventions suggest that you put constructor definitions before all other method
definitions.
15. False. There is only one constructor, because if a class contains a programmer-defined constructor, then the compiler does not provide a default constructor.
16. Use this syntax: this(<arguments-for-target-constructor>);
17. True.





































































   325   326   327   328   329