Solved

passing objects

Posted on 2012-03-14
1
193 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 500 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 38
table example 4 29
java stored proc example 9 32
eclipse buid path vs tomcat lib path 10 23
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

777 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