File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 19697
    
  20

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: 38910
    
  23
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: 19697
    
  20

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: 19697
    
  20

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