title: Kotlin Types, Subtypes, and Supertypes vs Classes, Subclasses and Superclasses
body: <p>I am learning about subtypes and supertypes in Kotlin, and initially assumed that these terms meant inherited and parent classes. But after reading <a href="https://hyperskill.org/learn/step/9689" rel="nofollow noreferrer">this post from JetBrains</a>, I am not sure I understand exactly what they mean by subtyping.</p>
  <p>The post explains that <code>Any</code> is a subtype of <code>Any?</code> (makes sense), <code>Number</code> is a subtype of <code>Any</code>, and <code>Int</code> is a subtype of <code>Number</code>. So far so good (<code>Any?</code> -&gt; <code>Any</code> -&gt; <code>Number</code> -&gt; <code>Int</code>), and (<code>Any?</code> -&gt; <code>Number?</code> -&gt; <code>Int?</code>).</p>
  <p>But notice diagram # 5:</p>
  <p><a href="https://i.stack.imgur.com/KRKUb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KRKUb.png" alt="enter image description here" /></a></p>
  <p>This diagram (and the accompanying text) imply and explain that <code>Number</code> is a subtype of its nullable counterpart <code>Number?</code>, and that <code>Int</code> is also a subtype of its nullable counterpart <code>Int?</code>. This sounds intuitive, until you remember that <code>Int</code> is also a subtype of <code>Number</code>, and <code>Number</code> a subtype of <code>Any</code>! This is in direct contradiction with the Kotlin docs which specify that</p>
  <p><em>Kotlin supports single-parent class inheritance - so each class (except the root class Any) has got exactly one parent class, called a superclass.</em></p>
  <p>I am left assuming that subtypes are not children classes per se (a single class can be a subtype of more than one parent class at once maybe?). If so, can someone clarify for me exactly what is meant by &quot;subtypes&quot; and &quot;supertypes&quot; in Kotlin?</p>