<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: The Ultimate Java Puzzler</title>
	<atom:link href="http://dow.ngra.de/2009/02/16/the-ultimate-java-puzzler/feed/" rel="self" type="application/rss+xml" />
	<link>http://dow.ngra.de/2009/02/16/the-ultimate-java-puzzler/</link>
	<description>no buzzwords allowed</description>
	<lastBuildDate>Wed, 24 Feb 2010 09:44:02 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jonathan</title>
		<link>http://dow.ngra.de/2009/02/16/the-ultimate-java-puzzler/comment-page-2/#comment-7390</link>
		<dc:creator>Jonathan</dc:creator>
		<pubDate>Sat, 28 Feb 2009 03:36:10 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=627#comment-7390</guid>
		<description>ah, I see the issue now.  My apologizes d :)</description>
		<content:encoded><![CDATA[<p>ah, I see the issue now.  My apologizes d :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jevgeni Kabanov</title>
		<link>http://dow.ngra.de/2009/02/16/the-ultimate-java-puzzler/comment-page-2/#comment-7382</link>
		<dc:creator>Jevgeni Kabanov</dc:creator>
		<pubDate>Sat, 28 Feb 2009 01:39:40 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=627#comment-7382</guid>
		<description>@jonathan

C4 has to be in p1, not p2.</description>
		<content:encoded><![CDATA[<p>@jonathan</p>
<p>C4 has to be in p1, not p2.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan</title>
		<link>http://dow.ngra.de/2009/02/16/the-ultimate-java-puzzler/comment-page-2/#comment-7376</link>
		<dc:creator>Jonathan</dc:creator>
		<pubDate>Sat, 28 Feb 2009 00:44:35 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=627#comment-7376</guid>
		<description>d,

What &quot;test case&quot; are you running?  Just for the hell of it, I put it into my IDE, and sure enough, C4.m() does not override C2.m() like I stated above.

You might want to read the link I posted above.

----------------------------
package p1;

public class C1 {
    int m() {return 1;}
}

----------------------------
package p1;

public class C2 extends C1 {
    int m() {return 2;}
}


----------------------------
package p1;

import p2.C4;

public class Main {
    public static void main(String[] args) {
        C1 c = new C4();
        System.out.println(c.m());
    }

}

----------------------------
package p2;

import p1.C2;

public class C3 extends C2 {
    int m() {return 3;}
}

----------------------------
package p2;

public class C4 extends C3 {

    int m() {return 4;}
}
----------------------------
Output:
2</description>
		<content:encoded><![CDATA[<p>d,</p>
<p>What &#8220;test case&#8221; are you running?  Just for the hell of it, I put it into my IDE, and sure enough, C4.m() does not override C2.m() like I stated above.</p>
<p>You might want to read the link I posted above.</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
package p1;</p>
<p>public class C1 {<br />
    int m() {return 1;}<br />
}</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
package p1;</p>
<p>public class C2 extends C1 {<br />
    int m() {return 2;}<br />
}</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
package p1;</p>
<p>import p2.C4;</p>
<p>public class Main {<br />
    public static void main(String[] args) {<br />
        C1 c = new C4();<br />
        System.out.println(c.m());<br />
    }</p>
<p>}</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
package p2;</p>
<p>import p1.C2;</p>
<p>public class C3 extends C2 {<br />
    int m() {return 3;}<br />
}</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
package p2;</p>
<p>public class C4 extends C3 {</p>
<p>    int m() {return 4;}<br />
}<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Output:<br />
2</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jevgeni Kabanov</title>
		<link>http://dow.ngra.de/2009/02/16/the-ultimate-java-puzzler/comment-page-2/#comment-7305</link>
		<dc:creator>Jevgeni Kabanov</dc:creator>
		<pubDate>Fri, 27 Feb 2009 16:09:19 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=627#comment-7305</guid>
		<description>@d

I think there&#039;s no way to call C2.m() from C4.m(). Granted, JVM will allow such a call via INVOKESPECIAL, but in the compiler super always refers to direct superclass and there is no other way to do that in Java.</description>
		<content:encoded><![CDATA[<p>@d</p>
<p>I think there&#8217;s no way to call C2.m() from C4.m(). Granted, JVM will allow such a call via INVOKESPECIAL, but in the compiler super always refers to direct superclass and there is no other way to do that in Java.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: d</title>
		<link>http://dow.ngra.de/2009/02/16/the-ultimate-java-puzzler/comment-page-1/#comment-7292</link>
		<dc:creator>d</dc:creator>
		<pubDate>Fri, 27 Feb 2009 13:37:10 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=627#comment-7292</guid>
		<description>If you run the test case, it is clear C4.m() does override C2.m(), even though C2.m() is not directly visible in C4.m(). The question is how to invoke the overridden method C2.m() in the overriding method C4.m(). The normal way of doing it by using super does not work in this case.</description>
		<content:encoded><![CDATA[<p>If you run the test case, it is clear C4.m() does override C2.m(), even though C2.m() is not directly visible in C4.m(). The question is how to invoke the overridden method C2.m() in the overriding method C4.m(). The normal way of doing it by using super does not work in this case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan</title>
		<link>http://dow.ngra.de/2009/02/16/the-ultimate-java-puzzler/comment-page-1/#comment-7232</link>
		<dc:creator>Jonathan</dc:creator>
		<pubDate>Fri, 27 Feb 2009 00:24:00 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=627#comment-7232</guid>
		<description>C4.m() does not override C2.m().  C2.m() is not visible to C4.m();

Even if everything was public (instead of package private), you cannot access C2.m() from C4.m() (unless of course C3.m() does not exist or class C3 providers some sort of method to get it like C3.getC2m()).  Regardless, if you&#039;re trying to do anything like this, it&#039;s time to rethink your design.</description>
		<content:encoded><![CDATA[<p>C4.m() does not override C2.m().  C2.m() is not visible to C4.m();</p>
<p>Even if everything was public (instead of package private), you cannot access C2.m() from C4.m() (unless of course C3.m() does not exist or class C3 providers some sort of method to get it like C3.getC2m()).  Regardless, if you&#8217;re trying to do anything like this, it&#8217;s time to rethink your design.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: d</title>
		<link>http://dow.ngra.de/2009/02/16/the-ultimate-java-puzzler/comment-page-1/#comment-7207</link>
		<dc:creator>d</dc:creator>
		<pubDate>Thu, 26 Feb 2009 20:15:20 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=627#comment-7207</guid>
		<description>Interesting discussions. I have a question. Since C4.m() overrides C2.m(), how can I invoke C2.m() from C4.m()&#039;s implementation? super.m() does not work. If you cast &quot;this&quot; to C2 and then invoke m(), as ((C2)this).m(), you get stack overflow as you are actually invoking yourself. There must be a way of doing it!</description>
		<content:encoded><![CDATA[<p>Interesting discussions. I have a question. Since C4.m() overrides C2.m(), how can I invoke C2.m() from C4.m()&#8217;s implementation? super.m() does not work. If you cast &#8220;this&#8221; to C2 and then invoke m(), as ((C2)this).m(), you get stack overflow as you are actually invoking yourself. There must be a way of doing it!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jevgeni Kabanov</title>
		<link>http://dow.ngra.de/2009/02/16/the-ultimate-java-puzzler/comment-page-1/#comment-6853</link>
		<dc:creator>Jevgeni Kabanov</dc:creator>
		<pubDate>Thu, 19 Feb 2009 16:22:46 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=627#comment-6853</guid>
		<description>@Hans-Peter

You still have a wrong mental model :) Which method is called does not depend on the caller, but rather on the target class in the call. Compiler resolved each call to the string Class.method(argsTypes)returnType. &quot;Class&quot; is a part of the message and vtable is selected by it. It&#039;s actually not so different from C++ if you think about implementation, but getting to the vtable is quite harder.</description>
		<content:encoded><![CDATA[<p>@Hans-Peter</p>
<p>You still have a wrong mental model :) Which method is called does not depend on the caller, but rather on the target class in the call. Compiler resolved each call to the string Class.method(argsTypes)returnType. &#8220;Class&#8221; is a part of the message and vtable is selected by it. It&#8217;s actually not so different from C++ if you think about implementation, but getting to the vtable is quite harder.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cgino</title>
		<link>http://dow.ngra.de/2009/02/16/the-ultimate-java-puzzler/comment-page-1/#comment-6847</link>
		<dc:creator>cgino</dc:creator>
		<pubDate>Thu, 19 Feb 2009 14:55:59 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=627#comment-6847</guid>
		<description>this test is a very good demonstration why one shouldnt go crazy with OO.
keeping things simple and away from over-sophistication ....saves so much.

do you want even more fun...jump into aspect-oriented progamming.</description>
		<content:encoded><![CDATA[<p>this test is a very good demonstration why one shouldnt go crazy with OO.<br />
keeping things simple and away from over-sophistication &#8230;.saves so much.</p>
<p>do you want even more fun&#8230;jump into aspect-oriented progamming.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sathish</title>
		<link>http://dow.ngra.de/2009/02/16/the-ultimate-java-puzzler/comment-page-1/#comment-6841</link>
		<dc:creator>Sathish</dc:creator>
		<pubDate>Thu, 19 Feb 2009 13:52:05 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=627#comment-6841</guid>
		<description>Thanks for the post, Kathy Sierra author of Sun certification exams has a good explanation about scopes as well.</description>
		<content:encoded><![CDATA[<p>Thanks for the post, Kathy Sierra author of Sun certification exams has a good explanation about scopes as well.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
