joshua-r2
10/25/2017 - 11:28 PM

Inner/Nested Class Example

Nested Classes do not have access to the outerclass variables/functions Inner classes can, but must be explicitly declared inner


class Tree(){

private val water = 23

  inner class branch(){
    private val water = 3
  
    fun printWaterLevels{
    
        //We can refer to outer class members explicitly using the @ notation
        println("Branch has water level of ${@branch.water})
        println("Tree has water level of ${@Tree.water}")
    }
  }
  
  class bark(){
  //cannot access Tree.water
    fun toughness: String{
      return "Tough"
    }
  }



}