<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Infinity &#187; Java</title>
	<atom:link href="http://blog.cyragon.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cyragon.com</link>
	<description>where it all begins</description>
	<lastBuildDate>Fri, 11 Feb 2011 20:26:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>C# vs Java: casting objects and calling members</title>
		<link>http://blog.cyragon.com/2011/02/c-vs-java-casting-objects-and-calling-members/</link>
		<comments>http://blog.cyragon.com/2011/02/c-vs-java-casting-objects-and-calling-members/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 20:24:00 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.cyragon.com/?p=210</guid>
		<description><![CDATA[Given these two functionally identical code samples in c# and java, what is the output? C#: public class A { &#160;&#160;public String Method() &#160;&#160;{ &#160;&#160;&#160;&#160;return &#34;this is A&#34;; &#160;&#160;} } public class B : A { &#160;&#160;public String Method() &#160;&#160;{ &#160;&#160;&#160;&#160;return &#34;this is B&#34;; &#160;&#160;} } A thisA = new B(); thisA.Method(); Java: public class [...]]]></description>
			<content:encoded><![CDATA[<p>Given these two functionally identical code samples in c# and java, what is the output?</p>
<p>C#:<br />
<pre><code>public class A
{
&nbsp;&nbsp;public String Method()
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;return &quot;this is A&quot;;
&nbsp;&nbsp;}
}

public class B : A
{
&nbsp;&nbsp;public String Method()
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;return &quot;this is B&quot;;
&nbsp;&nbsp;}
}

A thisA = new B();

thisA.Method();</code></pre></p>
<p>Java:<br />
<pre><code>public class A
{
&nbsp;&nbsp;public String Method()
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;return &quot;this is A&quot;;
&nbsp;&nbsp;}
}

public class B extends A
{
&nbsp;&nbsp;public String Method()
&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;return &quot;this is B&quot;;
&nbsp;&nbsp;}
}

A thisA = new B();

thisA.Method();</code></pre></p>
<p>What does thisA.Method() return? </p>
<p>It turns out that there are two different answers to this. In .NET/C# it returns from A (&#8220;this is A&#8221;). In Java, it returns from B (&#8220;this is B&#8221;). </p>
<p>So far it appears that this is a type issue; new B() must be getting cast back to A in C#. Looking for some documentation on this specifically. Links anyone?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cyragon.com/2011/02/c-vs-java-casting-objects-and-calling-members/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
