jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes after nullfiying the object in method, how does the object still able to access its instance variabl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "after nullfiying the object in method, how does the object still able to access its instance variabl" Watch "after nullfiying the object in method, how does the object still able to access its instance variabl" New topic
Author

after nullfiying the object in method, how does the object still able to access its instance variabl

Nagesh Reddy
Greenhorn

Joined: Jul 15, 2011
Posts: 2

// output
Object Created : Test.NullObjAccess@3e25a5
Object nullified : nagesh

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

You're reassigning the value of the parameter. Since Java is call-by-value only (in case of objects, the reference value is copied) that will not change the value of a outside the method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36578
    
  16
Welcome again. Please look through the contents pages for this forum and "Java in General"; there have been a few threads about pass by value very recently, which might be halpful.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234



Then why this program is changing the value from Ravi to RaviKiran





Save India From Corruption - Anna Hazare.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

Because you're not changing the reference, you're changing the actual object the reference is pointing to.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Yes , Thank you very much
Nagesh Reddy
Greenhorn

Joined: Jul 15, 2011
Posts: 2
thanks you so much..
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: after nullfiying the object in method, how does the object still able to access its instance variabl
 
Similar Threads
String explain output
asking about interfaces
Doubt-Khalid Mock Test,Q.No 14
why don't we change the arraylist element by reference?