A class has the following two methods:

float chargePenalty( int amount  ) { ... }
int   chargePenalty( int penalty ) { ... }
Do these methods have unique siqnatures?

A good answer might be:

No.


Return Type does Not Count

The names of the formal parameters are not part of the signature, nor is the return type. The signatures of the two methods are:

chargePenalty( int  )
chargePenalty( int  )

It might seem strange not to use the return type as part of the signature. The reason is that by doing this another problem is avoided. Say that there were two methods:

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

and that the main method made a call:

class CheckingAccountTester
{
  public static void main( String[] args )
  {
    
    CheckingAccount bobsAccount = new CheckingAccount( "999", "Bob", 100 );
    
    double result = bobsAccount.chargePenalty( 60 );

  }
}

Which method should be called? Since both int and float can be converted to double there is little reason to pick one over the other. (You might argue that float is closer to double than int, but there are other situations which are less clear.) To avoid confusion in situations like this, the return type is not counted as part of the signature.

QUESTION 14:

A class has the following two methods:

void changeInterestRate( double newRate  ) { ... }
void changeInterestRate( int    newRate  ) { ... }

Do these methods have unique siqnatures?