Meaningless Drivel is fun!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Arrays" Watch "Arrays" New topic


Shiva Arava

Joined: Feb 26, 2002
Posts: 2
Can I know why the value of the zeroth element of myValue is 3, and not 2, because the modifyIt method just increments it.
public class JavaTest
public static void main(java.lang.String[] args)
JavaTest test = new JavaTest();
int[] myValue = {1};
System.out.println("myValue contains " + myValue[0]);

System.out.println("myValue now contains " + myValue[0]);
public void modifyIt(int[] value)

Output : myValue contains 1
: myValue now contains 3
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Are you sure the code you've posted here is the same code you're running. I just ran it and got this:

This is just what I'd expect.

SCJP Tipline, etc.
Shiva Arava

Joined: Feb 26, 2002
Posts: 2
I checked the program, I get the value of myValue[0] as 2.
I agree. Here's the link:
subject: Arrays
It's not a secret anymore!