Professional Documents
Culture Documents
CSC201-Pass by Value
CSC201-Pass by Value
Parameters
Swap program
public class Main {
/**
* @param args the command line arguments
*/
}
}
Swap program
public class Main {
/**
* @param args the command line arguments
*/
}
}
Pass By Value
• In Java primitive variables are always passed by
value. That means, a copy of the variable is
passed into the method.
• If you make a change to the variable within the
method, then that change is not visible
elsewhere.
• In our swap() method, number1 and number2
were passed as parameters. Then they were
swapped. But when we tried printing the values
in our main method after swapping, they weren’t
changed.