Difference between arguments and parameters in java


I've seen many developers getting confused between parameter and argument, but it’s important to distinguish between them. Intention of this post is to give good understanding of few very frequently used terms in java.
argument
argument used in method call.

parameter
parameter is used in method definition.


program to give understanding of difference between parameter and argument
/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */
public class ParameterArgumentTest {
   public static void main(String[] args) {
          int a=3, b=4;
          sum(a,b); //a & b are arguments here
   }
   static void sum(int a, int b){ //a & b are parameters here
          System.out.println("sum = "+ (a+b));
   }
}

No comments:

Post a Comment