jQuery in Action, 3rd edition
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


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

public Test {
int x =0;

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

//main method excerpt
Test a= new Test();
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;
return b;

Hope this gives you a headstart
I agree. Here's the link: http://aspose.com/file-tools
subject: Final
jQuery in Action, 3rd edition