• 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 Objects

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 137
Hibernate Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Total Five String referential objects?
 
francis varkey
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rancher ,

Total 3 String objects will be created .
"Fred" and "47" are literals hence will be created before invocation of this method.
reply
    Bookmark Topic Watch Topic
  • New Topic