• 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

Doubt in Apress SCJP chapter 9 Question 8

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
8. Consider the following lines of code:
String s1 = "Whatever";
String s2 = new String("Whatever");
String s3 = new String ("Who");
Which of the following statements is true? (Choose all that apply.)
A. The compiler will create two strings Whatever and Who and put them in the pool, and
there will be a string Whatever and Who created at runtime.
B. The compiler will create two strings Whatever and Who and put them in the pool, and
there will be no string created at runtime.
C. The compiler will create two copies of Whatever and one copy of Who and put them in
the pool, and there will be strings Whatever and Who created at runtime.
D. The compiler will create one copy of Whatever and put it in the pool, and there will be
strings Whatever and Who created at runtime.
E. The compiler will create a string Whatever and put it in the pool, and there will be a
string Who created at runtime.

The given answer is A.
Just wondering if that is the correct answer (or how properly worded the question/answers are)
 
Ranch Hand
Posts: 153
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya That is correct, As per my knowledge in java if we type some thing inside the double quote "String" this creates a new String constant in String Constant Pool, and new keyword creates a new Object in heap.

here there two string constants "Whatever" and "Who" and again at run time we have 2 new to create two strings in heap

I think that helps
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have look on here
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
above article provide is great.

Happy Learning
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic