1+ public class ParametersArguments {
2+ //User-defined method to add two numbers
3+ public static int addNumbers (int a , int b ) {
4+ return a + b ;
5+ }
6+
7+ public static void main (String [] args ) {
8+ int result = addNumbers (3 , 5 );
9+ System .out .println ("Sum: " + result );
10+ }
11+ }
12+
113/* In Java, parameters are the variables listed in the method definition.
214
3- They act as placeholders for the values that the method can accept. For example, in the method:
15+ They act as placeholders for the values that the method can accept.
16+
17+ For example, in the method:
418
5- public static int addNumbers(int a, int b)
6- {
19+ public static int addNumbers(int a, int b) {
720 return a + b;
821}
922
10- Here, a and b are parameters. They define what kind of values the method addNumbers can accept (in this case, two integers).
11-
12- When you call the method, you pass arguments (actual values) to these parameters. For example:
23+ Here, a and b are parameters.
24+ They define what kind of values the method addNumbers can accept (in this case, two integers).
25+ When you call the method, you pass arguments (actual values) to these parameters.
1326
27+ For example:
1428addNumbers(3, 5);
15-
1629Here, 3 and 5 are arguments passed to the parameters a and b.
1730
1831In short:
19-
2032Parameters are defined in the method signature.
2133Arguments are the actual values passed to the method when it is called.
2234
2335Parameters:
24-
2536Defined in the method signature.
2637Act as placeholders for the values the method will receive.
2738
2839Example: In public static void greet(String name), name is a parameter.
2940
3041Arguments:
3142The actual values passed to the method when it is called.
32-
3343Example: In greet("Alice"), "Alice" is an argument passed to the name parameter.
3444
3545Key Difference:
3646Parameters are part of the method definition (what the method expects).
3747Arguments are the actual values you provide when calling the method.
38-
3948addNumbers(3, 5); → This is a method call that invokes the addNumbers method.
4049
4150call it a "Method Call" or "Method Invocation
4251*/
43-
44- public class ParametersArguments
45- {
46- /*User-defined method to add two numbers*/
47- public static int addNumbers (int a , int b )
48- {
49- return a + b ;
50- }
51-
52- public static void main (String [] args )
53- {
54- int result = addNumbers (3 , 5 );
55- System .out .println ("Sum: " + result );
56- }
57-
58- }
0 commit comments