go to previous page   go to home page   go to next page

Answer:

  1. statement A calls processDeposit(int)
  2. statement B calls processDeposit(int, int)

Method Signature

When several methods have the same name, only one is picked by a method call. The types of the actual parameters in a method call are matched with the types of the formal parameters of the methods. If an exact match cannot be made, then the actual parameters are converted to types that match the formal parameters if this can be done without potential loss of information.

For example, the call

bobsAccount.processDeposit( 200, 25 );  //statement A

matches this method declaration:

public void  
  processDeposit( int amount, int serviceCharge )

because the number and types of the actual parameters matches the number and types of the formal parameters.

The signature of a method is:

The signatures of the methods in a class must be unique. For example, the signatures of the two processDeposit methods are:

The names of the parameters are not part of the signature because parameter names are not visible outside of their scope.

The return type is not part of the signature. The visibility modifier is not part of the signature.


QUESTION 13:

Say that a class has the following two methods:

float chargePenalty( int amount  ) { ... }
int   chargePenalty( int penalty ) { ... }

Do these methods have unique signatures?