Originally posted by: Kilrsat
Amdfanboy's question about stack overflow might be a good warmup
<a target=_blank class=ftalternatingbarlinklarge href="http://forums.anandtech.com/me...eyword1=java">Stack Overflow Blues</a>
It would really demonstrate an understanding of inheritence and the problems you can run into when overriding some functions but not others.
Or why this code prints:
lalala
lalala
lalala
S1!=S2
S1=S3
S2!=S3
Originally posted by: vtqanh
<blockquote>quote:
<hr><i>Originally posted by: <b>Kilrsat</b></i>
Amdfanboy's question about stack overflow might be a good warmup
<a target=_blank class=ftalternatingbarlinklarge href="<a target=_blank class=ftalternatingbarlinklarge href="http://forums.anandtech.com/me...va">Stack</a> Overflow Blues</a>
It would really demonstrate an understanding of inheritence and the problems you can run into when overriding some functions but not others.
Or why this code prints:
lalala
lalala
lalala
S1!=S2
S1=S3
S2!=S3<hr></blockquote>
Interesting one. I was thinking that S1 would not equal to S3 as well, since the operation was checking if the two pointers were pointing to the same object.
S1 = new String("lalala");
S3 = new String("lalala");
S1 == S3 would yield false.
It gets into the Java String pool. Even though S1 and S3 are different objects according to the code both S1 and S3 actually point to the same object in the String pool. Its the String pool that creates issues with comparing strings because sometimes == does produce the expected results.Originally posted by: vtqanh
<blockquote>quote:
<hr><i>Originally posted by: <b>Kilrsat</b></i>
Amdfanboy's question about stack overflow might be a good warmup
<a target=_blank class=ftalternatingbarlinklarge href="<a target=_blank class=ftalternatingbarlinklarge href="http://forums.anandtech.com/me...va">Stack</a> Overflow Blues</a>
It would really demonstrate an understanding of inheritence and the problems you can run into when overriding some functions but not others.
Or why this code prints:
lalala
lalala
lalala
S1!=S2
S1=S3
S2!=S3<hr></blockquote>
Interesting one. I was thinking that S1 would not equal to S3 as well, since the operation was checking if the two pointers were pointing to the same object.
S1 = new String("lalala");
S3 = new String("lalala");
S1 == S3 would yield false.
Originally posted by: Kilrsat
<blockquote>quote:
<hr><i>Originally posted by: <b>vtqanh</b></i>
<blockquote>quote:
<hr><i>Originally posted by: <b>Kilrsat</b></i>
Amdfanboy's question about stack overflow might be a good warmup
<a target=_blank class=ftalternatingbarlinklarge href="<a target=_blank class=ftalternatingbarlinklarge href="<a target=_blank class=ftalternatingbarlinklarge href="http://forums.anandtech.com/me...ck</a></a> Overflow Blues</a>
It would really demonstrate an understanding of inheritence and the problems you can run into when overriding some functions but not others.
Or why this code prints:
lalala
lalala
lalala
S1!=S2
S1=S3
S2!=S3<hr></blockquote>
Interesting one. I was thinking that S1 would not equal to S3 as well, since the operation was checking if the two pointers were pointing to the same object.
S1 = new String("lalala");
S3 = new String("lalala");
S1 == S3 would yield false.<hr></blockquote>
It gets into the Java String pool. Even though S1 and S3 are different objects according to the code both S1 and S3 actually point to the same object in the String pool. Its the String pool that creates issues with comparing strings because sometimes == does produce the expected results.
Originally posted by: BingBongWongFooey
null and null? DescendantData needs to call its init() in its constructor. Better yet, just ditch init() and use the constructor to initialize; that's its purpose.
Originally posted by: dighn
<blockquote>quote:
<hr><i>Originally posted by: <b>BingBongWongFooey</b></i>
null and null? DescendantData needs to call its init() in its constructor. Better yet, just ditch init() and use the constructor to initialize; that's its purpose.<hr></blockquote>
1 null
the base's constructor still gets called implicitly
Originally posted by: BingBongWongFooey
<blockquote>quote:
<hr><i>Originally posted by: <b>dighn</b></i>
<blockquote>quote:
<hr><i>Originally posted by: <b>BingBongWongFooey</b></i>
null and null? DescendantData needs to call its init() in its constructor. Better yet, just ditch init() and use the constructor to initialize; that's its purpose.<hr></blockquote>
1 null
the base's constructor still gets called implicitly<hr></blockquote>
Aha. Tricky indeed! <img src="i/expressions/face-icon-small-smile.gif" border="0">
Originally posted by: kamper
Whoops, dighn, you are correct, sorry. Can you explain why it's not:
1
2
Hint: DescendantData.init() <b>does</b> get called.
BingBong: I know the constructor should be used for initialization. There was a reason why we had a situation like this that is not apparent in this example because it's been stripped down to just demonstrate the tricky part.
Originally posted by: kamper
On the non-technical side you could ask them design things like why you shouldn't expose data members of a class publicly (more of a beginner question).
You could also maybe ask something about how protected actually means package-access.
