Java Reference
In-Depth Information
΢΢΢ Exercise R8.21. How can you write a method that swaps two
floating-point numbers? Hint: Point2D.Double .
΢΢ Exercise R8.22. Draw a memory diagram that shows why the following
method can't swap two BankAccount objects:
public static void falseSwap(BankAccount a,
BankAccount b)
{
BankAccount temp = a;
a = b;
b = temp;
}
378
379
΢ Exercise R8.23. Consider an enhancement of the Die class of Chapter 6
with a static field
public class Die
{
public Die(int s) {. . .}
public int cast() {. . .}
private int sides;
private static Random generator = new
Random();
}
Draw a memory diagram that shows three dice:
Die d4 = new Die(4);
Die d6 = new Die(6);
Die d8 = new Die(8);
Be sure to indicate the values of the sides and generator fields.
΢ Exercise R8.24. Try compiling the following program. Explain the error
message that you get.
public class Print13
{
public void print(int x)
{
Search WWH ::




Custom Search