title: Kotlin Polymorphism Confusion
body: <p>I was following a tutorial for learning kotlin and ran into this example.</p>
  <pre><code>open class AquariumPlant(val color: String, private val size: Int)
  
  class GreenLeafyPlant(size: Int) : AquariumPlant(&quot;green&quot;, size)
  
  fun AquariumPlant.print() = println(&quot;AquariumPlant&quot;)
  fun GreenLeafyPlant.print() = println(&quot;GreenLeafyPlant&quot;)
  
  val plant = GreenLeafyPlant(size = 10)
  plant.print()
  println(&quot;\n&quot;)
  val aquariumPlant: AquariumPlant = plant
  aquariumPlant.print()  // what will it print?
  </code></pre>
  <p>Well this apparently prints &quot;Aquarium Plant&quot; instead of &quot;GreenLeafyPlant&quot;. I was a bit confused by this so I tested this out with this little snippet of code.</p>
  <pre><code>open class Aquarium {
      open fun printSize() {
          println(&quot;hello&quot;)
      }
  }
  
  class TowerTank: Aquarium() {
      override fun printSize() {
          println(&quot;rawr&quot;)
      }
  }
  
  fun main() {
      towerTank = TowerTank()
      (towerTank as Aquarium).printSize()
  }
  </code></pre>
  <p>So this prints &quot;rawr&quot; and not &quot;hello&quot;. My question is why doesn't it print &quot;hello&quot;? Aren't these two examples contradicting themselves? How does the function extensions create this difference in behaviour? Sorry if this may seem like a dumb question, I'm new to Kotlin as you can probably tell.</p>