× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

JAVA: are the notion of subtyping and of inheritance the same thing?

James Jensen
Feb 10, 2015
<p>The footnote reads:</p> <blockquote> <p>As it happens the notion of <em>"subtype"</em> is not entirely in line with <em>"inherits from"</em>: Interfaces with no super interface are indeed subtypes of <code>Object</code> (<a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.10.2" rel="nofollow">§ 4.10.2. Subtyping among Class and Interface Types </a>) even though they do not inherit from <code>Object</code>.</p> </blockquote> <p>Interfaces can only extend other interfaces--none of them actually <code>extends Object</code>, <em>either explicitly or implicitly</em>. And yet, all of the <code>Object</code> methods are available on every interface. This makes an interface like <code>List&lt;&gt;</code> a <em>subtype</em> of <code>Object</code>--it has all the method signatures that <code>Object</code> would have--even though the interface itself does not inherit <em>implementations</em> of those methods from the <code>Object</code> class.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/25552730/JAVA:%20are%20the%20notion%20of%20subtyping%20and%20of%20inheritance%20the%20same%20thing?/25552954">Stack Overflow</a>.</p>
comments powered by Disqus