This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strings Doubt

 
gobburi saikrishna
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers

This question is from one of Mock exam

public String makinStrings() {
String s = �Fred�;
s = s + �47�;
s = s.substring(2, 5);
s = s.toUpperCase();
return s.toString();
}
How many String objects will be created when this method is invoked?
A. 1
B. 2
C. 3
D. 4
E. 5
F. 6

Answer is C, my doubt is why cant answer be E
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... If they are making the distinction I think they are, this is tricky wording that I would not expect on the real exam.

I would say that there are a total of 5 String objects here, but the 2 literals are created when the class is loaded, and this question is asking how many are created when the method is invoked.

(See Strings, Literally.)
 
Nevin kumar
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when class is loaded how come method local literals are created without explicitly calling the method.I disagree with weber.when class is loaded only static things are initialized(like static variables & blocks)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic