I am a bit confused for one concept in String.Suppose I have below code:
How many objects are created above.I thought two objects but since first string "abc" will go into string pool,so z will just point to this string and no new object will get created.Can anyone explain it more clearly.
Variations of this question have been asked many many times already on this forum. Use the Search Tool to find them.
My initial response to a question like this though is "who cares!". In nearly a decade of programming for a living, and plenty more years programming for a hobby, I have never needed to know. So it's fairly unlikely you do either. My advice is to forget about it and move on.
Tushar Goel wrote:Agree with both of your points but this is typical interview question...
Yeah, but IMO it's a bad one, because it makes people think about where objects are and how many they're creating; which is precisely what Java was intending to avoid. I have the same view about a lot of stuff in the SCJP exam.
However, the world is what it is; and there may still be team leaders around who worry about this sort of stuff.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
We don't have time to be charming! Quick, read this tiny ad: