- /**
- * Illustrates the
difference between an argument and a
- * parameter.
- *
- * @author tkrogers
- * @version 9-27-11
- */
- public class ArgumentParameterDemo {
- public static void main ( )
{
- int
x;
- int
number = 4;
-
// here the someMethod is being called or
-
// in other words run. the 2 is an argument.
-
// It is the data value passed into someMethod
-
// for processing.
- x =
someMethod ( 2 );
-
System.out.println ( "someMethod returns " + x);
- //
Now number is used as an argument. Its
-
// value of 4 is now passed into someMethod
-
// for processing
-
someMethod ( number );
-
System.out.println ( "someMethod returns " + x);
-
// Note: arguments NEVER have a data type. They are
-
// only found when a method is called.
- }
-
- // The line of code below
this comment is a
- // specification for
someMethod. " int i" is a
- // parameter.Parameters
specify the type of data
- // that will be passed into
the method for processing.
- public static int
someMethod ( int i) {
-
return 2 * i;
- }
- // Note: Parameters always
show a data type and
- // are only found in the
first line of a method's code.
- }