Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium



Posted on 2006-05-06
Medium Priority
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
  • 2
LVL 24

Accepted Solution

sciuriware earned 1200 total points
ID: 16623822
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

ID: 16623840
LVL 24

Expert Comment

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

Glad to help you.


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

578 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