CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #4
    Join Date
    Feb 2017
    Posts
    674

    Re: pass by value and pass by reference in Java?

    Quote Originally Posted by kadammanali987 View Post
    What is the difference between pass by value and pass by reference in Java?
    The parameter passing mechanism in Java is always by_value. The by_reference passing mechanism doesn't exist in Java. It means whatever you pass (a primitive or a reference) to a method it will be copied before it is available in the method.

    It's important to understand that objects are always represented/handled indirectly by so called references in Java. A reference can be thought of as a "pointer" to an object. Therefore you could claim that "in Java an object is passed by its reference" but that doesn't mean the passing mechanism is by_reference (in the computer science sense of the term). So a reference is passed indeed but it is by_value, hence the confusion.
    Last edited by wolle; December 9th, 2018 at 07:09 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured