wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from valiveru mock exam 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 "Question from valiveru mock exam" Watch "Question from valiveru mock exam" New topic
Author

Question from valiveru mock exam

sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
Hi,
I would like to know the answer for this question. How many strings are created in the follo program.
String s1,s2,s3,s4;
s1 = "Hello";
s2 = s1; //s2="Hello"
s3 = s2 + "Pal"; //s3="Hello Pal"
s4 = s3;//s4="Hello Pal"
According to me, 2 strings(Hello & Hello Pal) are created. But the ans given is 3.
can anyone explian this?
-Sanjana
David Hadiprijanto
Ranch Hand

Joined: Sep 14, 2003
Posts: 52
Sanjana,

in the above line, two strings are created, "Pal" and "Hello Pal".
Hence, the answer to the question is 3 strings are created, "Hello", "Pal", and "Hello Pal".
Hope this helps.
dennis zined
Ranch Hand

Joined: Mar 07, 2003
Posts: 330
A new String is created at s1. s2 points to the same string as s1 but no new strings are created. A new String "Pal" is created (which makes the count now to 2) and another string forming "Hello Pal" (count now is three). s4 points to the same string as s3 but no new strings are created.


SCJP 1.4<br />SCWCD 1.4
srini v
Greenhorn

Joined: Dec 15, 2003
Posts: 11
Dear All:
In debug mode, when constructing a string, I want go into string constructor source.
I am using JBuilder6.
Cheers
dennis zined
Ranch Hand

Joined: Mar 07, 2003
Posts: 330
In debug mode, when constructing a string, I want go into string constructor source

IDE's and Other Tools should be the proper forum for your post
sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
Thank u guys..
-Sanjana
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question from valiveru mock exam
 
Similar Threads
Questions from mock exam
String object
String Objects
please help me
question...