This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String Objects" Watch "String Objects" New topic
Author

String Objects

francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 166
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: 166
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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
 
Similar Threads
String Objects...
How many String objects will be created?
please provide the explanation regarding string objects............
How many String objects are created?
how many String objects created??