Difference between Argument and Parameter in Java
In this section, we are going to learn a difference between Argument and Parameter in Java. They both caries the same value but actually they are different from each other.
- Argument is a variable whose value is passed into a function and is used whenever a function is called. Parameter is the value that is defined in a functional block. So, it is basically used whenever we need to pass a value to a particular functional block.
- Arguments are used to send the values to the function whereas parameters are used to receive or hold the values of arguments.
- During a function call, each argument is associated with a parameter and vice versa is also true.
- Arguments are called the actual parameter whereas parameters are called formal parameters.
Java program to understand the difference between Argument and Parameter
package CodeSpeedy; public class ArgumentVsParameter { public static void main(String[] args) { // TODO Auto-generated method stub String a="Code"; String b="Speedy"; System.out.println("In the main block"); String c=concatenation(a,b); //a and b are arguments System.out.println(c); } public static String concatenation(String x,String y) { // x and y are parameters System.out.println("In the functional block"); return x+y; } }
Output:
In the main block In the functional block CodeSpeedy
Leave a Reply