• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Again the string.......help!!

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


The answer given is 1, 2 and 3

for thee 4th option, the reason for why it's wrong is given as :
Option 4 is incorrect because the strings which are computed at runtime are distinct and hence DO NOT share same instances. There is one exception to this rule and that is the strings which are constructed from other strings which are declared as final do share same instances.

can anyone explain with some example whatever is here in bold.

thanx
amit
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Option 4 is incorrect because the strings which are computed at runtime are distinct and hence DO NOT share same instances. There is one exception to this rule and that is the strings which are constructed from other strings which are declared as final do share same instances.


hey Amit,
look at the program below, hope it makes u understand


So ur second case explains u ur doubt. U can see that the Strings declared in the second case are final which means they are going to be resolved during compile time and hence variable "ssumF" results to true. Hence the output.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic