Arguments in Java with Examples


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); }
Code language: Java (java)

Hope this article is helpful to you. If you like Techarge and would like to contribute, you can also write an article using or mail your article to [email protected] . See your article appearing on the Techarge home page and help other to learn. 🙂

20%off for Ink 280 281

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More