-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassByValue.java
More file actions
38 lines (30 loc) · 979 Bytes
/
PassByValue.java
File metadata and controls
38 lines (30 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* This program demonstrate that only a copy of an argument
* is passed into a method.
*/
public class PassByValue
{
public static void main(String[] args)
{
int number = 99; //number starts with 99
//Display the value in number.
System.out.println("number is "+ number);
//call changeMe, passing the value in number
//as an argument.
changeMe(number);
//Display the value in number again.
System.out.println("number is "+ number);
}
/**
* The changeMe method accepts an argument and the
* changes the value of the parameter.
*/
public static void changeMe(int myValue)
{
System.out.println("I am changing the value.");
//Change the myValue parameter variable to 0.
myValue = 0;
//Display the value in myValue.
System.out.println("Now the value is "+ myValue);
}
}