Posted on 2006-05-06
Last Modified: 2010-03-31
Hi, I have a question that I got stuck with while studying my review study guide. The question is:

When an object is passed to a method in Java, the formal parameter will contain a reference to the object. Explain why we say that Java uses pass-by-value (not pass-by-reference, as you might expect)?

My guess would be because resulting value is copied into a location being used to hold the formal parameter's value during method/function execution. Am I right?
Question by:shahrine99
    LVL 24

    Accepted Solution

    Yes right, and that value is a copy of the reference to that object,
    so that the object might be changed if allowed, but the original reference is untouched.
    That's the principle of by-value.

    Note that here -by-reference and -by-value are near.
    In some language, the object itself might be offered as a copy, but not here.

    The only important difference of -by-value -by-reference exists where we pass
    variables themselves, in order to change something at the caller.

    In JAVA all method parameters are copies (values or references).


    Author Comment

    LVL 24

    Expert Comment

    You'll never know how this pleased me on a difficult time.

    Glad to help you.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    Hibernate:  App generating error messages in production 2 29
    countX 22 49
    json example 39 77
    solarwind tftp server 2 16
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now