joshua-r2
10/24/2017 - 8:12 PM

Access Modifiers

Access modifiers help control the level of visibility of a class's inner workings, properties, and implementation details. See below for example implementations.

Notes: *Extension functions do not have access to private and protected *Outer classes cannot see into inner class private members. *Constructors can be private



class Automobile(){


// "Public" can be accessed from anywhere
//  This is the default accessor if none is specified
public var color: String

//"Internal" is only visible from within a Module (the set of Kotlin files compiled together
internal var hasNavigation: Boolean

//"Private" is only visible within the class
private val dieselEmissionCode: String

//"Protected" is visible from subclasses
protected var transmissionType: String

  class ArchitecturePlatform(){
    
    //note that in contrast to Javathis private variable is NOT accessible from Automobile
    private val vehicleType: String
  }


}