Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Originally posted by Sachin Kapoor:
In Question 1, when newName is assigned string "Jason", string "Nick" is left with no references. Then when newName is assigned variable name, string "Jason" is left with no references. So that's two String objects with no references, "Nick" and "Jason". That is why I thought the answer is 2.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
SCJP 5.0 | SCWCD 1.4
Originally posted by Fred Rosenberger:
there's your problem. newName is not assigned to variable name. newestName is.
[ August 14, 2007: Message edited by: Fred Rosenberger ]
In this sample there is no object eligible for garbage collection. The code uses only string literals, and the objects for those are created at class loading time.Originally posted by Sachin Kapoor:
String name;
String newName = "Nick";
newName = "Jason";
name = "Frieda";
String newestName = name;
name = null;
SCJP 5 <br />SCWCD <br />Next: ?
Solve this code:<br /> <br />10010101100001111011011000010100000111001011011111100011110101111100110100001
Sandeep Atluri
MooN
SCJP 5.0 | SCWCD 1.4
It runs on an internal combustion engine. This ad does not:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|