K. Tsang wrote:You want to find that out yourself. Do a equals test and a "==" test. The "==" should return false. The only reason the "==" returns true for Strings is that they are pointing to the "same" object.
I thought about that, but I couldn't say whether or not this constituted proof of an object being created "inside a heap". I'm not to clear on that aspect.
Fred Hamilton wrote:I thought about that, but I couldn't say whether or not this constituted proof of an object being created "inside a heap". I'm not to clear on that aspect.
Hmm maybe the K&B SCJP excerpt (ch 3 OO) will convince:
For the most part, the various pieces (methods, variables, and objects) of Java
programs live in one of two places in memory: the stack or the heap. For now, we're
going to worry about only three types of things: instance variables, local variables,
* Instance variables and objects live on the heap.
* Local variables live on the stack.
So what is String? a object so where is it created? on the heap. And in my code, how many string objects? 1, 2, or 3?
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop