up previous next contents
Next: Overriding methods Up: Classes and objects Previous: this   Contents

Overloading methods

  • Each method has a signature.
  • The signature is (a) the name together with (b) the number and (c) types of parameters.
  • Two methods in the same class can have the same name if they have different numbers or types of parameters.
  • This capability is called overloading.
  • The compiler compares the number and types of parameters to find the method that matches the signature.
  • The signature does not include the return type or list of thrown exceptions, and you cannot overload based on these factors.
      public void aMethod(String s) {}
      public void aMethod() {}
      public void aMethod(int i, String s) {}
      public void aMethod(String s, int i) {}
    


up previous next contents
Next: Overriding methods Up: Classes and objects Previous: this   Contents