Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

passing objects

Posted on 2012-03-14
1
Medium Priority
?
199 Views
Last Modified: 2012-03-14
If I instantiate an object in my application's main class, and then pass it to the constructor of another class which will need to use it, does the copy/assignment of the object to something local actually make another object?
Generic example below:
Class A {
ClassB B = new ClassB();
ClassC C = new ClassC(B);
}

Class C {
ClassB localB = null;
Class C (ClassB B) {
  localB = B;
}
}
0
Comment
Question by:dpalyca755
1 Comment
 
LVL 1

Accepted Solution

by:
nareshvoota earned 2000 total points
ID: 37723038
Java is always pass by value but when you pass a reference to a method, the reference gets copied over. But it still points to the old object.

Please read this discussion in stackoverflow

http://stackoverflow.com/questions/40480/is-java-pass-by-reference

In your case,  localB is referring to the new class B object that is made in class A.

Hope this helps.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

782 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