File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why does value not change???" Watch "why does value not change???" New topic

why does value not change???

maggie karve
Ranch Hand

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

Choose: 1


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

Joined: Dec 30, 2009
Posts: 3
void deleteSharpen(Sharpen sharpen)
sharpen = null;
sharpen = new Sharpen();

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) will get output "mothulla"
I agree. Here's the link:
subject: why does value not change???
It's not a secret anymore!