aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why does value not change??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why does value not change???" Watch "why does value not change???" New topic
Author

why does value not change???

maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
What is the output of this program ?

Choose: 1

Options

1.) FunnyMan

2.) seizure

3.) mothulla

4.) NullPointerException

5.) Compile time error

answer is seizure..i expected it to be mothulla...since the set method calls setname method and sets it value to mothulla....
if anybody has understood kindly explain..thanks in advance
Lokesh Varma
Greenhorn

Joined: Dec 30, 2009
Posts: 3
void deleteSharpen(Sharpen sharpen)
{
sharpen = null;
sharpen = new Sharpen();
sharpen.setName("mothulla");
}

In the above function the argument "sharpen" is local to method. It is shadowing the instance variable "sharpen". You are making local variable to NULL. change the argument to any other name as shown below:

void deleteSharpen(Sharpen sharpen1).....you will get output "mothulla"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why does value not change???
 
Similar Threads
How to call InnerClass method...Help..Urgent
Problem with BeanUtils
Clarifications/Suggestions in Java
how to accept an instance of a class as a parameter
How can I get a run() method to return a string variable, when run() method is required to be void ?