• 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

String == returns true?

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

Copyright � Tony Morris 2005




What is the output and why?

  • false false false false false false
  • true true true true true true
  • false true false true false true
  • false true false false true false
  • false true false true false false
  • compile-time error ________
  • runtime exception ________
  • something else ________



  • Answer
    The correct answer is E

    Why do we get true?
     
    Ranch Hand
    Posts: 657
    Spring VI Editor Clojure
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The string literals are determined at compile time and are pooled.

    Here's a good read: String literals
     
    Steve Morrow
    Ranch Hand
    Posts: 657
    Spring VI Editor Clojure
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Oh, and as to why the first one is false and the second true, the final keyword lets the compiler know that value will never change; thus, the resulting literal can be determined at compile-time and pooled, as previously described.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic