SCJP 6
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
I thought there are only 2 objects created.i.e at line 14 and 15.
Where is the third object
SCJP 6
SCJP 6
SCJP 6
nancy gurudatta wrote:final String s="abc";//created at compile time
String s1=s+"def";//created at compile time as it is constant expression
String s2=s+"def";//created at compile time as it is constant expression
System.out.println(s1==s2);//true
Hi Punit,
Tell Me..
There will be 2 objects created in above code..
Am I right???
SCJP 6
Srinivasan Jayakumar wrote:Hello Friends,
i have preparing for SCJP 5.0, i had a doubt the following question
Given:
11. public String makinStrings() {
12. String s = “Fred”;
13. s = s + “47”;
14. s = s.substring(2, 5);
15. s = s.toUpperCase();
16. return s.toString();
17. }
How many String objects will be created when this method is invoked?
A. 1
B. 2
C. 3
D. 4
E. 5
F. 6
Roses are red, Violets are blue. Strings are immutable, Wrappers are too. (HFJ)
SCJA 1.0 (86%), SCJP 6.0 (91%)
Abhi vijay wrote:Can anyone explain about String objects created at runtime and compile time? I am really getting confused.
Here,
String s3="hel"+"lo"; // is it a runtime/ compile time object?![]()
SCJP 6
It will be created at compile time Abhi, as it contains "hel" and "lo" both are constant String literal.
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
James Tharakan wrote:
It will be created at compile time Abhi, as it contains "hel" and "lo" both are constant String literal.
I thought hel and lo are compile time literals (literal pool).
And during runtime s3 gets a new object hello :?:
SCJP 6
Abhi vijay wrote:Punit,
Here in Line1 s4 should be created at compile time, as s1, s2 both are created at compile time???
SCJP 6
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
SCJP 6
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
James Tharakan wrote:
I wish String class is not a final class. All this confusion could be avoided.![]()
SCJP 6
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
SCJP 6
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |