Is this problem difficult to prevent?

A good answer might be:

No---usually all the instance variables are declared in one place in the class definition and it is easy to check them.

Method Overloading

Overloading is when two or more methods of a class have the same name but have different parameter lists. When one of the methods is called (by main() or by some other method) it is clear which one is wanted by matching the actual parameter list to the formal parameter lists.

Here is a further modification of the CheckingAccount class:

class CheckingAccount
{
  . . . .
  private int    balance;

  . . . .
  void  processDeposit( int amount )
  {
    balance = balance + amount ; 
  }

  void  processDeposit( int amount, int serviceCharge )
  {
    balance = balance + amount - serviceCharge; 
  }

}

Say that two processDeposit( ) methods were needed:

  • One for ordinary deposits, for which there is no service charge.
  • One for other deposits, for which a service charge can be made.

The above code implements these requirements. Here is an example main() method that uses both methods:

class CheckingAccountTester
{
  public static void main( String[] args )
  {
    CheckingAccount bobsAccount = new CheckingAccount( "999", "Bob", 100 );
    bobsAccount.processDeposit( 200 );       // first call
    bobsAccount.processDeposit( 200, 25 );   // second call
  }
}

QUESTION 12:

Which of the following is true?

  1. The first      call calls the first      processDeposit() method.
  2. The first      call calls the second processDeposit() method.
  3. The second call calls the first      processDeposit() method.
  4. The second call calls the second processDeposit() method.
Click Here after you have answered the question