This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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: 187
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???