Parameter and Arguments

Parameter and Arguments



We use parameters in Java language to hold input/output data in Java methods.

Information can be passed to methods as parameter. Parameters act as variables inside the method.

Parameters are specified after the method name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma.

The following example has a method that takes a String called fname as parameter. When the method is called, we pass along a first name, which is used inside the method to print the full name:











Argument

Example

            


            float area(float height,float width){

                    float ar=height*width;

                    System.out.Println(ar);

            return (ar)

            }

Here float height and float width are given as parameters. Also, the Argument of that method is given as 10, 20. Those two values are substituted for the float height and float width parameters of the respective method and the relevant task is performed and printed through the return type.


Here are some key features.

  • void return type can be used with any data type,
  • We can use some data types as return types. Its specialty is that those data types can return only relevant data.
  • When we use void return type, the return keyword should not be used in the method.
  • But if we use some data types as a return type, we must use the return keyword in the method.
  • But if we use some data types as a return type, we should never provide data of a data type opposite to that data type as its argument.


No comments:

Post a Comment

Pages