HTML Java

Java Method


Method Body

This is where all the method operations take place. We write all the statement inside the curly brackets to perform specific task by the method.



What is method Signature?

Method signature consists of name and parameter type declare in order. Many method can have in the class but with different signature.

public void setEmployeeDetails(int id,String name,String Address) {
}
public int setEmployeeDetails(int id,String name,String Address) {
}

If we write these 2 method inside a class then it will give an error because both the methods have same signature.

You can change method like this.

public void setEmployeeDetails(String id,String name,String Address) {
}
Or
public void setEmployeeDetails(int id,String name,String Address,String city) {
}

Example:

package com.sofstack.util
public class Addition{
public int addTwoNumbers (int x, int y) {
return x + y;
}
public static void main(String args[]){
Addition add = new Addition();
int sum = add.addTwoNumbers(5,4);
System.out.println(" Sum of two number is " +sum);
}
}