Home Java Program Examples Arguments in Java with Examples

Arguments in Java with Examples

by anupmaurya
2 minutes read

An argument is a value passed to a function when the function is called. Whenever any function is called during the execution of the program there are some values passed with the function. These values are called arguments. An argument when passed with a function replaces those variables which were used during the function definition and the function is then executed with these values.

Types of Arguments

Actual arguments:

The arguments that are passed in a function call are called actual arguments. These arguments are defined in the calling function.

Formal arguments:

The formal arguments are the parameters/arguments in a function declaration. The scope of formal arguments is local to the function definition in which they are used. Formal arguments belong to the called function. Formal arguments are a copy of the actual arguments. A change in formal arguments would not be reflected in the actual arguments.

Let’s look have a look on an example:

public class ArgumentExp
{      // a & b are the formal arguments, there scope is within the function definition 
      public static int add(int a, int b)
       return a+b;
public void main(string [] args)
      int a=10 ;
      int b=30;
       /* a and b are actual arguments, they are passed during a function call */ 
      int sum=add(a,b);
      System.out.println("SUM of number :"+sum);

Hope this article is helpful to you. If you like Techarge and would like to contribute, you can also write an article using https://techarge.in/start-blogging-with-us/ or mail your article to techarge.in@gmail.com . See your article appearing on the Techarge home page and help other to learn. 🙂

You may also like

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.