0

just wanted to know why this program prints "25 and 7", instead of "25 and 25".

int b = 7;
int c = b;
b = 25;

System.out.print(b + " and " + c)

I am a little bit confused because the variable b has been replaced by the new value of 25, then why c still has its same value of 7?

Thank you in advance!

Esmeraldo
  • 35
  • 7
  • Primitives are not referenced, only composite data types are! – dryairship Jun 28 '16 at 12:34
  • 2
    http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value – Nicolas Filotto Jun 28 '16 at 12:35
  • Refer more specifically to this answer in the linked question http://stackoverflow.com/a/40499/1743880: *For primitive arguments (int, long, etc.), the pass by value is the actual value of the primitive (for example, 3).* – Tunaki Jun 28 '16 at 12:36

0 Answers0