Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Final

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Folks,

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

 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It gives the same output without the final keywords. So what's this got to do with final?
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic