aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt regarding refernce variable passing to method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt regarding refernce variable passing to method" Watch "Doubt regarding refernce variable passing to method" New topic
Author

Doubt regarding refernce variable passing to method

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Hi

Please have a look at the following code:



The output is 100 100 1 1 1. When we pass the reference variable h1, the copy of bits that refer to the object referred to by h1 on heap are passed to the method doStuff(). Correct? Then why is it printing 100 again for h1 roomNr? It should print 1 .


~ Mansukh
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1174
Why does the following code return 100 100 1 1 1 explains it.


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

So when we say inside the method doStuff, we are creating a new reference hotel and the original h1 reference remains unchanged. Correct?
Zhenyi Luo
Ranch Hand

Joined: Sep 03, 2012
Posts: 33
Mansukhdeep Thind wrote:So when we say inside the method doStuff, we are creating a new reference hotel and the original h1 reference remains unchanged. Correct?


You are right.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt regarding refernce variable passing to method