Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Final Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Final" Watch "Final" New topic
Author

Final

Sathya Shanmugam
Ranch Hand

Joined: Mar 02, 2007
Posts: 45
hi Folks,

Could anyone please explain how the result is " true true "

Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
It gives the same output without the final keywords. So what's this got to do with final?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Meena R. Krishnan
Ranch Hand

Joined: Aug 13, 2006
Posts: 178
AFter the call to FizzSwitch(), both f3 and f1 are the same and both have the same value of 6 which got assigned in the switch method.

FizzSwitch() takes f1 as its first arg, and assigns the value of 6 by temporarily assigning it to z and returns f1.
swarna dasa
Ranch Hand

Joined: Mar 15, 2007
Posts: 108
when you declare an object final then it means that you can not change the reference to another object, but the objects state can be changed.

final Test o = new Test();
o= new Test(); //CANNOT BE DONE
o.x=9; //CAN BE DONE

where
public Test {
int x =0;
}

Also when you pass an argument to the method you pass a COPY OF THE REFERENCE.

so
//main method excerpt
Test a= new Test();
a.x=7;
Test q =method(a); //Now q.x value is 45 and a.x is 45
//if b=null is uncommented then q will be null and a.x will be 45


static Test method (Test a) {
Test b=a;
b.x=45;
//b=null;
return b;
}


Hope this gives you a headstart
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Final
 
Similar Threads
doubt in chapter 3 k&B book
Need help
Use of final keyword with class object.
explain this code
chapter 3 self test question 5, K&B