public BankAccount()
{
private double balance;
}
public BankAccount()
{
balance = 0;
}
public BankAccount(double initialBalance)
{
balance = initialBalance;
}
BankAccount harrysChecking = new BankAccount(1000);
public void deposit(double amount)
{
balance = balance + amount;
}
harrysChecking.deposit(500);
public void withdraw(double amount)
{
balance = balance - amount;
}
public double getBalance()
{
return balance;
}
Suppose we modify the BankAccount class so that each bank account has an account number. We add an instance variable
private int accountNumber;
Where else do we need to make changes?
The Rectangle class has four instance variables: x, y, width, and height. Which of the following is an appropriate body for the method
public void translate(int dx, int dy)
width = width + dx; height = height + dy;
int newx = x + dx; x = newx; int newy = y + dy; y = newy;
x = x + width; y = y + height;
dx = x + dx; dy = x + dy;
When you run the BankAccountTester program, how many objects of class BankAccount are constructed? How many objects of type BankAccountTester?
BankAccountTester, no objects of
BankAccountBankAccountTester, no objects of
BankAccountBankAccountTester, one object of
BankAccountBankAccountTester, one object of
BankAccountpublic double giveChange()
{
double change = payment - purchase;
purchase = 0;
payment = 0;
return change;
}
public void enterPayment(double amount)
null for objects), but you must initialize local
variablesWhat does the following program segment print?
public void printArea()
{
int area;
int width = 10;
int height = 20;
System.out.println(area);
}
200
Expected: 200
Consider this class:
public class Label
{
private String text;
private int start;
public int end() { return start + text.length();
}
What is the result of executing
System.out.println(new Label().end());
0
null0