pass by value doc
TRANSCRIPT
-
8/14/2019 Pass by Value Doc
1/3
-
8/14/2019 Pass by Value Doc
2/3
public class Main {
public static void myabsvalue(int mynumber)
{
System.out.println("I am in method myabsvalue");mynumber = Math.abs(mynumber);
System.out.println(mynumber);
}
public static void main(String[] args) {
// TODO code application logic here
int num = -4;System.out.println("Number is:"+num);
myabsvalue(num);
System.out.println("I am in main method");
System.out.println("Value of num is:"+num);
}
}
The above is the example with different parameter names. The result is the same. This
depicts the pass by value in Java.
Talking of scope, it is described below:
In your main method define the below
for(int i=0; i
-
8/14/2019 Pass by Value Doc
3/3
P.S : A local variable is the one which is accessible only within the function or block
where it is declared.
Pass By Reference: Later.