Ah - there are several problems here. I think the first thing you need to know is that the String pool, the intern() method, and similar functionality for wrapper classes, are
not on the exam. You don't need to worry about this. You do need to know that any time you construct any object using new, you create a new object which is not part of any pool. This is true whether we're talking about a String or a wrapper.
Additional details may be of interest, but since this is in the
SCJP topic for some reason, let's remind people: you don't need to worry about this stuff.
But, for those who are nonetheless curious...
[rajeshwar]: 2)The two strings which return same constant expression during compile time they are said to be interned and if it is different they are not interned. If the strings are represented by compile-time constant expressions, the values of those strings are interned, period. If they're the same, then both strings are represented by the same interned String instance. If they're different, then they are represented by two different interned String instances.
[rajeshwar]: So here str3 and str4 are interned.
and str3 and str5 are not interned. Hunh? You've contradicted yourself about str3. In your example, only str4 is interned; all the others (str1, str2, str3, str5) are not. You may want to study the definition of
compile-time constant expression to understand why
[rajeshwar]: my question is even wrapper classes are treated as objects like strings then why they are not interned like strings. I addressed this earlier in my previous post - did you read it?
[ March 22, 2006: Message edited by: Jim Yingst ]