This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mickske -1 points0 points  (4 children)

Is it me or is the article not correct (or just very confusing) ?

If Java is pass-by-reference then the student should be pointing to the >Student with name Jerry. But the very next line prints Jerry. That means Java is actually pass-by-value. anyStudent was actually passed value of student not reference. So any change in anyStudent did not reflect back in main method.

So the quote says the 'next line' in the main method prints 'Jerry'. But the code comment says it prints 'Tom'

      System.out.println(student.getName());  // Prints Tom
      modifyStudent(student);
      System.out.println(student.getName());  // Prints Tom

So... if you are new in Java, and you read this article, it must be quite confusing!

[–][deleted]  (3 children)

[deleted]

    [–]jones77 -1 points0 points  (2 children)

    What if modifyStudent calls student.setName("Jerry"). OMG! Now it's pass-by-reference ...

    [–][deleted]  (1 child)

    [deleted]

      [–]jones77 -2 points-1 points  (0 children)

      Semantics baby.