Google+ Badge

Friday, 29 January 2016

Difference between arguments and parameters in Java

Parameter is defined in the method header whereas an argument is the instance passed to the method during run-time.
public class Parameters and Arguments {

    public static int divide(int a, int b) { //a, b are parameters here
         a=5;
         b=5;
        return a%b;

    }

    public static void main(String[] args) {
        int x=divide(a, b); //a, b are arguments here
        System.out.println(x);
    }

}
Here a and b are formal parameters which is declared in the method's header. 
Whereas the a and b becomes arguments in the point of invocation.