Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

String is an immutable object.
Then how can the following code be justified.

String s1 = ?ABC?;
String s1 = s1+?XYZ?;
s.o.p(s1);

The output is ABCXYZ, which is the value of s1 ?

Answer Posted / amr

actually its a compiler error , variable already defined ..

but i'll answer the other part ,
String is immutable but does it make sense to write
String S1= abc;
S1=s1+"def";
YEAH its immutable and what happens behind the scene :
a new temporary String is created and using StringBuffer
which mutable class then appending then returning the
temporary string , thats the meaning of String is immutable
but StringBuffer is mutable , so if u r gonna use intensive
String manipulation u better go for StringBuffer because
String concatenation will result in more lines of code in
the byte code file generated when we compile .
this is a very frequent interview question .

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the difference between jdk, jre, and jvm?

994


what is the final keyword denotes in java?

1021


Explain JMS in detail.

972


Explain why wait(), notify() and notifyall() methods are in object class rather than in the reading class?

923


Explain java coding standards for constants?

952


What languages are pass by reference?

989


What is the difference between a checked and an unchecked exception?

927


What a static class can contains?

1106


Can we use different return types for methods when overridden?

942


What is the use of static class?

1083


What happens when I use / and % with a negative numerator?

995


Can we have try without catch block?

1030


Name component subclasses that support painting in java programming?

1013


How do I remove a character from a string in java?

920


What is the difference between method overriding and overloading?

1173