Java Reference
In-Depth Information
private int x;
private int y;
private int width;
private int height;
9.
public int getWidth()
{
return width;
}
10. There is more than one correct answer. One possible implementation is as
follows:
public void translate(int dx, int dy)
{
int newx = x + dx;
x = newx;
int newy = y + dy;
y = newy;
}
11. One
BankAccount
object, no
BankAccountTester
object. The
purpose of the
BankAccountTester
class is merely to hold the
main
method.
12. In those environments, you can issue interactive commands to construct
BankAccount
objects, invoke methods, and display their return values.
13. Variables of both categories belong to methodsČthey come alive when the
method is called, and they die when the method exits. They differ in their
initialization. Parameter variables are initialized with the call values; local
variables must be explicitly initialized.
14. One instance field, named
balance
. Three local variables, one named
harrysChecking
and two named
newBalance
(in the
deposit
and
withdraw
methods); two parameter variables, both named
amount
(in
the
deposit
and
withdraw
methods).
131
132
15. One implicit parameter, called
this
, of type
BankAccount
, and one
explicit parameter, called
amount
, of type
double
.