| Author |
String Objects
|
francis varkey
Ranch Hand
Joined: Sep 13, 2005
Posts: 155
|
|
Respected Sirs, public String makeStrings() { 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 Thnks Francis
|
 |
Sidharth Pallai
Ranch Hand
Joined: Apr 21, 2008
Posts: 134
|
|
|
Total Five String referential objects?
|
Thanks & Regards
Sidharth Pallai
|
 |
francis varkey
Ranch Hand
Joined: Sep 13, 2005
Posts: 155
|
|
But the question providers say the answer is 3: I think there is 6: 1) "Fred" 2) "47" 3)"Fred47" 4)"ed4" 5)"ED4" 6)"ED4" , while calling toString() can anyone help with explabation
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12911
|
|
Try searching the forums for "Fred 47". This exact same question has been asked and answered here many times. For example: How many string object created in this code String Test Strings Q from javaBeat on String Strings Doubt Strings doubt with string abjects How many object create? ... [ July 01, 2008: Message edited by: Jesper Young ]
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Sunny Mattas
Ranch Hand
Joined: Apr 22, 2008
Posts: 45
|
|
Read questiobnm carefully It ask's for number of strings objects created when method is invoked i.e. at runtime. I think there are three string objects being created when program runs. Others are created at compile time. Regards Sunny
|
Regards
Sunny Mattas
SCJP5
|
 |
Madhukar Ojha
Ranch Hand
Joined: Mar 21, 2007
Posts: 71
|
|
Hi Rancher , Total 3 String objects will be created . "Fred" and "47" are literals hence will be created before invocation of this method.
|
SCJP 5 ๑۩۞۩๑♥~~ My Life is My Creation ~~♥๑۩۞۩๑
|
 |
 |
|
|
subject: String Objects
|
|
|