Method Signature

Method Signature in Java

In Java, a method signature consists of the method name and the parameter types of the method. It uniquely identifies a method within a class or an interface. The return type and the method's visibility (modifiers) are not part of the method signature.

Example:

Consider the following class with multiple methods:

    
      class MyClass {
          public void printMessage(String message) {
              System.out.println(message);
          }
      
          public int addNumbers(int a, int b) {
              return a + b;
          }
      }
    
  

In the above example, the MyClass has two methods:

  • printMessage(String message) - Method signature: printMessage(String)
  • addNumbers(int a, int b) - Method signature: addNumbers(int, int)

The method signatures include the method names and the parameter types. They provide a way to uniquely identify each method within the class.

Go To OOPS Page Click Here

Post a Comment

Previous Post Next Post