SE450: Basics: Passing Parameters [32/63] |
What does the following print?
file:Main.java [source] [doc-public] [doc-private]
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
package basics.swap; public class Main { private Main() {} static public void main (String[] args) { //stdlib.Trace.graphvizShowSteps (true); stdlib.Trace.showBoxedPrimitivesAsPrimitive(false); stdlib.Trace.run (); Integer x = 42; Integer y = 27; Main.swap(x,y); System.out.println(x); System.out.println(y); } static private void swap (Integer a, Integer b) { Integer t = a; a = b; b = t; } }
Java is call-by-value.
Call by Value Links
Cup Size -- a story about variables
by JavaRanch.
By JavaRanch.
Does Java pass by reference or pass by value? Why can't you swap in Java?
By Tony Sintes.