Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin-Workshop Day #1

Kotlin-Workshop Day #1

Android Academy TLV - Kotlin workshop

Co-created with
Eden Bugdary Machluf and Hadas Peled

Avatar for Gil Goldzweig

Gil Goldzweig

October 15, 2019
Tweet

More Decks by Gil Goldzweig

Other Decks in Programming

Transcript

  1. What Do We Do? • Kotlin workshop • Fundamentals •

    Design • Hackathon • Advanced • Partner Events • Mentors Program
  2. What Do We Do? • Kotlin workshop • Fundamentals •

    Design • Hackathon • Advanced • Partner Events • Mentors Program
  3. Mentors Alexey Korolev Alex Vainshtein Benny Pivnic David Harush Hezi

    Dimri Hazi Corly Ben Michaeli Avishay Peretz Andrey Lebedev Eugene Rozenberg David Vardi Lior Prigal Maya Gorel Michael Groenendijk Orit Malki Rebecca Hamelsdorf Ronen Sabag Regev Avraham Sergio Geralnik Yossi Rizgan Daniel Szasz
  4. Schedule 17:00- 17:30 - lecture 17:30-18:00 - hands on 18:00-18:30-

    lecture 18:30-18:50 - hands on 18:50 - 19:00 - coffee break 19:00-19:30- lecture 19:30-20:00 - hands on 20:00-20:30- lecture 20:30-21:00 - hands on
  5. Today syllabus ▢ Workspace ▢ Operators ▢ Variables ▢ Null

    safety ▢ Strings ▢ Conditions ▢ Arrays & loops ▢ Ranges ▢ Functions ▢ Classes
  6. Basic operators • Common operators: ◦ + , - ,

    * , / ◦ When we use Int the result will be Int and so on. println(2 * "Bye ") => Bye Bye ◦ Can be used with any type
  7. Difference between var and val • val - Immutable reference

    - The variable cannot be changed once the value is assigned. It is similar to final variable in Java.
  8. Difference between var and val • val - Immutable reference

    - The variable cannot be changed once the value is assigned. It is similar to final variable in Java. • var - Mutable reference - The variable can be changed later in the program. It corresponds to regular Java variable.
  9. Difference between var and val • val - Immutable reference

    - The variable cannot be changed once the value is assigned. It is similar to final variable in Java. • var - Mutable reference - The variable can be changed later in the program. It corresponds to regular Java variable.
  10. var b: String? = null How to declare a nullable

    reference? Differentiate between nullable references and non-nullable references.
  11. var b: String? = null How to declare a nullable

    reference? Differentiate between nullable references and non-nullable references.
  12. var b: String? = null How to declare a nullable

    reference? Differentiate between nullable references and non-nullable references.
  13. var b: String? = null How to declare a nullable

    reference? Differentiate between nullable references and non-nullable references.
  14. var b: String? = null How to declare a nullable

    reference? Differentiate between nullable references and non-nullable references.
  15. var b: String = null How to declare a nullable

    reference? Differentiate between nullable references and non-nullable references.
  16. var b: String = null How to declare a nullable

    reference? Differentiate between nullable references and non-nullable references.
  17. Kotlin NullPointerException • When you ask for a NullPointerException explicitly

    ◦ throw NullPointerException() ◦ Use !! operator. • From Outside Kotlin • Data inconsistency
  18. Kotlin NullPointerException • When you ask for a NullPointerException explicitly

    ◦ throw NullPointerException() ◦ Use !! operator. • From Outside Kotlin • Data inconsistency
  19. Kotlin NullPointerException • When you ask for a NullPointerException explicitly

    ◦ throw NullPointerException() ◦ Use !! operator. • From Outside Kotlin • Data inconsistency
  20. Kotlin NullPointerException • When you ask for a NullPointerException explicitly

    ◦ throw NullPointerException() ◦ Use !! operator. • From Outside Kotlin • Data inconsistency
  21. How Kotlin handles Null Safety ? • Differentiate between nullable

    references and non-nullable references. • User explicitly checks for a null in conditions • Using a Safe Call Operator ?. • Elvis Operator ?: : If reference to a val is not null, use the value, else use some default value that is not null
  22. How Kotlin handles Null Safety ? • Differentiate between nullable

    references and non-nullable references. • User explicitly checks for a null in conditions • Using a Safe Call Operator ?. • Elvis Operator ?: : If reference to a val is not null, use the value, else use some default value that is not null
  23. How Kotlin handles Null Safety ? • Differentiate between nullable

    references and non-nullable references. • User explicitly checks for a null in conditions • Using a Safe Call Operator ?. • Elvis Operator ?: : If reference to a val is not null, use the value, else use some default value that is not null
  24. How Kotlin handles Null Safety ? • Differentiate between nullable

    references and non-nullable references. • User explicitly checks for a null in conditions • Using a Safe Call Operator ?. • Elvis Operator ?: : If reference to a variable is not null, use the value, else use some default value that is not null
  25. Elvis Operator val b: String? = null val bLength: Int

    = b?.length // ERROR - Type mismatch: inferred type is Int? but Int was // expected
  26. String templates val math = 100 val english = 90

    val diploma = "math: " + math + "\nenglish: " + english
  27. String templates val math = 100 val english = 90

    val diploma = "math: " + math + "\nenglish: " + english math: 100 english: 90
  28. String templates val math = 100 val english = 90

    val diploma = "math: $math \nenglish: $english" math: 100 english: 90
  29. String templates val math = 100 val english = 90

    val diploma = "math: $math \nenglish: $english" math: 100 english: 90
  30. String templates val math = 100 val english = 90

    val diploma = "math: $math \nenglish: $english" math: 100 english: 90
  31. String templates val math = 100 val english = 90

    val diploma = "math: $math \nenglish: $english" val average = "average: ${(math + english) / 2}"
  32. String templates val math = 100 val english = 90

    val diploma = "math: $math \nenglish: $english" val average = "average: ${(math + english) / 2}"
  33. String templates val math = 100 val english = 90

    val diploma = "math: $math \nenglish: $english" val average = "average: ${(math + english) / 2}"
  34. String templates val math = 100 val english = 90

    val diploma = "math: $math \nenglish: $english" val average = "average: ${(math + english) / 2}" average: 95
  35. If // With else var max: Int if (a >

    b) { max = a } else { max = b }
  36. If // With else var max: Int if (a >

    b) { max = a } else { max = b }
  37. If // With else var max: Int if (a >

    b) { max = a } else { max = b }
  38. If // With else var max: Int if (a >

    b) { max = a } else { max = b }
  39. If // With else var max: Int if (a >

    b) { max = a } else { max = b }
  40. If // With else var max: Int if (a >

    b) { max = a } else { max = b }
  41. If // With else var max: Int if (a >

    b) { max = a } else { max = b } // Traditional usage var max = a if (max < b) max = b
  42. If // With else var max: Int if (a >

    b) { max = a } else { max = b } // Traditional usage var max = a if (max < b) max = b
  43. If // With else var max: Int if (a >

    b) { max = a } else { max = b } // Traditional usage var max = a if (max < b) max = b
  44. If // With else var max: Int if (a >

    b) { max = a } else { max = b } // Traditional usage var max = a if (max < b) max = b
  45. When when (x) { 1 -> print("x == 1") 2

    -> print("x == 2") else -> { // Note the block print("x is neither 1 nor 2") } }
  46. When when (x) { 1 -> print("x == 1") 2

    -> print("x == 2") else -> { // Note the block print("x is neither 1 nor 2") } }
  47. When when (x) { 1 -> print("x == 1") 2

    -> print("x == 2") else -> { // Note the block print("x is neither 1 nor 2") } }
  48. When when (x) { 1 -> print("x == 1") 2

    -> print("x == 2") else -> { // Note the block print("x is neither 1 nor 2") } }
  49. When when (x) { 1 -> print("x == 1") 2

    -> print("x == 2") else -> { // Note the block print("x is neither 1 nor 2") } }
  50. When when (x) { 1 -> print("x == 1") 2

    -> print("x == 2") else -> { // Note the block print("x is neither 1 nor 2") } }
  51. When when (x) { 1 -> print("x == 1") 2

    -> print("x == 2") else -> { // Note the block print("x is neither 1 nor 2") } }
  52. When when (x) { 1 -> print("x == 1") 2

    -> print("x == 2") else -> { // Note the block print("x is neither 1 nor 2") } }
  53. When when (x) { 1 -> print("x == 1") 2

    -> print("x == 2") else -> { // Note the block print("x is neither 1 nor 2") } }
  54. When when (x) { 1 -> print("x == $x") 2

    -> print("x == $x") else -> { // Note the block print("x is neither 1 nor 2") } }
  55. When when (x) { 1,2 -> print("x == $x") else

    -> { // Note the block print("x is neither 1 nor 2") } }
  56. When when (x) { 1,2 -> print("x == $x") else

    -> { // Note the block print("x is neither 1 nor 2") } }
  57. When when { x.isOdd() -> print("x is odd") s.isEven() ->

    print("s is even") else -> print("else") }
  58. When when { x.isOdd() -> print("x is odd") s.isEven() ->

    print("s is even") else -> print("else") }
  59. public class MyTest { @Test fun test() { var subject

    = TestSubject() subject.method() // dereference directly } }
  60. public class MyTest { @Test fun test() { var subject

    = TestSubject() subject.method() // dereference directly } }
  61. public class MyTest { var subject: TestSubject @SetUp fun setup()

    { subject = TestSubject() } @Test fun test() { subject.method() // dereference directly } }
  62. public class MyTest { var subject: TestSubject @SetUp fun setup()

    { subject = TestSubject() } @Test fun test() { subject.method() // dereference directly } } ?
  63. public class MyTest { var subject: TestSubject @SetUp fun setup()

    { subject = TestSubject() } @Test fun test() { subject.method() // dereference directly } } lateinit
  64. Typed arrays • Array of specific type val numbers =

    intArrayOf(10 , 20 , 30) => [10, 20 ,30] val chars = charArrayOf('1' , '2' , '3') => ['1' , '2' , '3'] val doubleNumbers = doubleArrayOf(1.0 , 2.5 , 3.0) => [1.0 , 2.5 , 3.0]
  65. Typed arrays • Array of specific type val numbers =

    intArrayOf(10 , 20 , 30 , "Eden")
  66. Untyped arrays val notOnlyNumbers = arrayOf(10 , 20 , 30

    , "Eden") =>[10 , 20 , 30 , "Eden"]
  67. Arrays- dynamic init val squares = Array(5) { i ->

    (i * i).toString() } Cell index (iterator)
  68. Arrays- dynamic init val squares = Array(5) { i ->

    (i * i).toString() } Cell content
  69. Arrays- dynamic init val squares = Array(5) { i ->

    (i * i).toString() } Casting to String
  70. Arrays- dynamic init val squares = Array(5) { i ->

    (i * i).toString() } => ["0", "1", "4", "9", "16"]
  71. For loops val names = arrayOf("Ori", "Shir", "Adi") for (name

    in names) { println(name) } Iterate read only variable
  72. For loops val names = arrayOf("Ori", "Shir", "Adi") for (name

    in names) { println(name) } Iterable object
  73. For loops val names = arrayOf("Ori", "Shir", "Adi") for (name

    in names) { println(name) } //output Ori Shir Adi
  74. For loops .with index for ((index, value) in names.withIndex()) {

    println("Cell #$index: name is $value") }
  75. For loops .with index for ((index, value) in names.withIndex()) {

    println("Cell #$index: name is $value") }
  76. For loops .with index for ((index, value) in names.withIndex()) {

    println("Cell #$index: name is $value") }
  77. For loops .with index for ((index, value) in names.withIndex()) {

    println("Cell #$index: name is $value") }
  78. For loops .with index for ((index, value) in names.withIndex()) {

    println("Cell #$index: name is $value") } => Cell #0: the name is Ori Cell #1: the name is Shir Cell #2: the name is Adi
  79. Ranges if (i >= 1 && i <= 4) {

    print("Valid") } for (int i = 1; i != 4; i++) { print(i) }
  80. Ranges if (i in 1..4) { print("Valid") } for (int

    i = 1; i != 4; i++) { print(i) }
  81. Ranges if (i in 1..4) { print("Valid") } for (i

    in 1..4) { print(i) // Outputs -> 1, 2, 3, 4 }
  82. Ranges for (i in 1..8 step 2) print(i) // Outputs

    -> 1, 3, 5, 7 for (i in 8..1 step 2) print(i)
  83. Ranges for (i in 1..8 step 2) print(i) // Outputs

    -> 1, 3, 5, 7 for (i in 8 downTo 1 step 2) print(i)
  84. Ranges for (i in 1..8 step 2) print(i) // Outputs

    -> 1, 3, 5, 7 for (i in 8 downTo 1 step 2) print(i) // Outputs -> 8, 6, 4, 2
  85. Ranges for (i in 1..8 step 2) print(i) // Outputs

    -> 1, 3, 5, 7 for (i in 8 downTo 1 step 2) print(i) // Outputs -> 8, 6, 4, 2 for (i in 0..array.length) { array[i] }
  86. Ranges for (i in 1..8 step 2) print(i) // Outputs

    -> 1, 3, 5, 7 for (i in 8 downTo 1 step 2) print(i) // Outputs -> 8, 6, 4, 2 for (i in 0..array.length) { array[i] //Runtime exception IndexOutOfBounds }
  87. Ranges for (i in 1..8 step 2) print(i) // Outputs

    -> 1, 3, 5, 7 for (i in 8 downTo 1 step 2) print(i) // Outputs -> 8, 6, 4, 2 for (i in 0..array.length - 1) { array[i] }
  88. Ranges for (i in 1..8 step 2) print(i) // Outputs

    -> 1, 3, 5, 7 for (i in 8 downTo 1 step 2) print(i) // Outputs -> 8, 6, 4, 2 for (i in 0..array.length - 1) { array[i] //Everything works }
  89. Ranges for (i in 1..8 step 2) print(i) // Outputs

    -> 1, 3, 5, 7 for (i in 8 downTo 1 step 2) print(i) // Outputs -> 8, 6, 4, 2 for (i in 0 until array.length) { array[i] //Everything works }
  90. Ranges for (i in 1..8 step 2) print(i) // Outputs

    -> 1, 3, 5, 7 for (i in 8 downTo 1 step 2) print(i) // Outputs -> 8, 6, 4, 2 for (i in 0 until array.length) { array[i] //Everything works } for (i in 'a'..'c') print(i)
  91. Ranges for (i in 1..8 step 2) print(i) // Outputs

    -> 1, 3, 5, 7 for (i in 8 downTo 1 step 2) print(i) // Outputs -> 8, 6, 4, 2 for (i in 0 until array.length) { array[i] //Everything works } for (i in 'a'..'c') print(i) // Outputs -> 'a', 'b', 'c'
  92. If expression val max = if (i in 1..4) {

    print("I is valid") i } else { print("I is not valid") 4 }
  93. If expression val max = if (i in 1..4) {

    print("I is valid") i } else { print("I is not valid") 4 }
  94. If expression val max = if (i in 1..4) {

    print("I is valid") i } else { print("I is not valid") 4 }
  95. If expression val max = if (i in 1..4) {

    print("I is valid") i } else { print("I is not valid") 4 }
  96. If expression val max = if (i in 1..4) {

    print("I is valid") i } else { print("I is not valid") 4 }
  97. If expression val max = if (i in 1..4) {

    print("I is valid") i } else { print("I is not valid") 4 }
  98. If expression val max = if (i in 1..4) {

    print("I is valid") i } else { print("I is not valid") 4 }
  99. when expression val isPretty = when (speaker) { "Gil Goldzweig"

    -> true "Hadas Peled" -> true "Eden Bugdary" -> true else -> false }
  100. when expression val isPretty = when (speaker) { "Gil Goldzweig"

    -> { print("Speaker is awesome") true } "Hadas Peled" -> true "Eden Bugdary" -> true else -> false }
  101. Functions - default values fun greeting(name: String = "Android"): String

    { return "Hello " + name } greeting() // Output -> Hello Android greeting("Gil") // Output -> Hello Gil
  102. Functions - named arguments fun greeting(name: String, age: Int): String

    { return "Hello " + name + "your age " + age }
  103. Functions - named arguments fun greeting(name: String, age: Int): String

    { return "Hello " + name + "your age " + age } greeting("Gil", 19)
  104. Functions - named arguments fun greeting(name: String, age: Int): String

    { return "Hello " + name + "your age " + age } greeting("Gil", 19) greeting(age = 19, name = "Gil")
  105. Functions - named arguments fun greeting(name: String = "Gil", age:

    Int): String { return "Hello " + name + "your age " + age }
  106. Functions - named arguments fun greeting(name: String = "Gil", age:

    Int): String { return "Hello " + name + "your age " + age } greeting(age = 19)
  107. Functions - single line function fun greeting(name: String, age: Int):

    String { return "Hello " + name + "your age " + age }
  108. Functions - single line function fun greeting(name: String, age: Int):

    String = "Hello " + name + "your age: " + age
  109. Functions - single line function fun greeting(name: String, age: Int):

    String = "Hello " + name + "your age: " + age
  110. Filters - example val names = arrayOf("Ori", "Shir", "Adi", "Oren")

    println( names.filter {it[0] == 'O'} ) collection of items
  111. Filters - example val names = arrayOf("Ori", "Shir", "Adi", "Oren")

    println( names.filter {it[0] == 'O'} ) condition
  112. Filters - example val names = arrayOf("Ori", "Shir", "Adi", "Oren")

    println( names.filter {it[0] == 'O'} ) => [Ori, Oren]
  113. Filters - Eager/Lazy • By default filter is eager. Everytime,

    the filter creates a new list of the elements that pass through the filter.
  114. Filters - Eager/Lazy What about lazy? • For lazy we

    can use a sequence. ◦ Sequence - a collection that can only look at one item at a time.
  115. Filters - Lazy val sequenceONames = names.asSequence().filter {it[0] == 'O'}

    println( sequenceONames.toList() ) //[Ori, Oren]
  116. Lambdas - function types val growth: (Int) -> Int =

    { students: Int -> students * 2 }
  117. Lambdas - function types val growth: (Int) -> Int =

    { students: Int -> students * 2 }
  118. Lambdas - function types val growth: (Int) -> Int =

    { students: Int -> students * 2 }
  119. Lambdas - example val currentStudents = 100 val growth: (Int)

    -> Int = { students -> students * 2 } println("new students counts is " + growth(currentStudents) )
  120. Lambdas - example val currentStudents = 100 val growth: (Int)

    -> Int = { students -> students * 2 } println("new students counts is " + growth(currentStudents) )
  121. Lambdas - example val currentStudents = 100 val growth: (Int)

    -> Int = { students -> students * 2 } println("new students counts is " + growth(currentStudents) )
  122. Lambdas - example val currentStudents = 100 val growth: (Int)

    -> Int = { students -> students * 2 } println("new students counts is " + growth(currentStudents) )
  123. Lambdas - example val currentStudents = 100 val growth: (Int)

    -> Int = { students -> students * 2 } println("new students counts is " + growth(currentStudents) )
  124. Lambdas - example val currentStudents = 100 val growth: (Int)

    -> Int = { students -> students * 2 } println("new students counts is " + growth(currentStudents) ) //new students counts is 200
  125. Lambdas - example val currentStudents = 100 val growth: (Int)

    -> Int = { students -> students * 2 } println("new students counts is " + growth(currentStudents) ) //new students counts is 200
  126. Classes class IceCream(var flavor: String = "Vanilla", val cone: Boolean

    = true) val vanillaCone = IceCream() val chocolateCone = IceCream("Chocolate")
  127. Classes class IceCream(var flavor: String = "Vanilla", val cone: Boolean

    = true) val vanillaCone = IceCream() val chocolateCone = IceCream("Chocolate") val vanillaCup = IceCream(cone = false)
  128. Classes class IceCream(var flavor: String = "Vanilla", val cone: Boolean

    = true) val vanillaCone = IceCream() val chocolateCone = IceCream("Chocolate") val vanillaCup = IceCream(cone = false)
  129. Classes - Declaring Properties class IceCream(var flavor: String = "Vanilla",

    val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" }
  130. Classes - Declaring Properties class IceCream(var flavor: String = "Vanilla",

    val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" var flavorString = "I taste like $flavor" }
  131. Classes - Declaring Properties class IceCream(var flavor: String = "Vanilla",

    val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" var flavorString: String? }
  132. Classes - Declaring Properties class IceCream(var flavor: String = "Vanilla",

    val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" var flavorString: String? } // ERROR: Property must be initialized or be abstract.
  133. Classes - Declaring Properties class IceCream(var flavor: String = "Vanilla",

    val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" var flavorString: String? } // ERROR: Property must be initialized or be abstract.
  134. Classes - Declaring Properties class IceCream(var flavor: String = "Vanilla",

    val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" val flavorString: String? } // ERROR: Property must be initialized or be abstract.
  135. Classes - Declaring Properties class IceCream(var flavor: String = "Vanilla",

    val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" val flavorString: String? init { flavorString = "I taste like $flavor" } }
  136. Classes - Declaring Properties class IceCream(var flavor: String = "Vanilla",

    val cone: Boolean = true){ val cup = !cone val base = if(cup) "cup" else "cone" val flavorString: String? init { flavorString = "I taste like $flavor" } }
  137. Classes - Declaring Properties var <propertyName>[: <PropertyType>] [= <property_initializer>] [<getter>]

    [<setter>] val flavorString: String? init{ flavorString = "I taste like $flavor" }
  138. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" }
  139. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" }
  140. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" }
  141. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" }
  142. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla get() = this.flavor == "Vanilla" }
  143. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla = false get() = this.flavor == "Vanilla" } // ERROR - Initializer is not allowed here because // this property has no backing field
  144. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla get() = this.flavor == "Vanilla" }
  145. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" } val iceCream = IceCream()
  146. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" } val iceCream = IceCream()
  147. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" } val iceCream = IceCream() println(iceCream.isVanilla)
  148. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" } val iceCream = IceCream() println(iceCream.isVanilla)
  149. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" } val iceCream = IceCream() println(iceCream.isVanilla)
  150. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" } val iceCream = IceCream() println(iceCream.isVanilla)
  151. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" } val iceCream = IceCream() println(iceCream.isVanilla) // true
  152. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" } val iceCream = IceCream() println(iceCream.isVanilla) // true iceCream.flavor = "Chocolate"
  153. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" } val iceCream = IceCream() println(iceCream.isVanilla) // true iceCream.flavor = "Chocolate" println(iceCream.isVanilla)
  154. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" } val iceCream = IceCream() println(iceCream.isVanilla) // true iceCream.flavor = "Chocolate" println(iceCream.isVanilla)
  155. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla: Boolean get() = this.flavor == "Vanilla" } val iceCream = IceCream() println(iceCream.isVanilla) // true iceCream.flavor = "Chocolate" println(iceCream.isVanilla) // false
  156. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla get() = this.flavor == "Vanilla" }
  157. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ val isVanilla get() = this.flavor == "Vanilla" }
  158. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" }
  159. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" } // ERROR: Property must be initialized.
  160. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } }
  161. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } }
  162. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } }
  163. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } }
  164. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate")
  165. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}")
  166. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}") Chocolate , false
  167. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}") Chocolate , false
  168. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}") Chocolate , false
  169. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}") iceCream.isVanilla = true
  170. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}") iceCream.isVanilla = true
  171. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}") iceCream.isVanilla = true
  172. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}") iceCream.isVanilla = true println("${iceCream.flavor} , ${iceCream.isVanilla}")
  173. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}") iceCream.isVanilla = true println("${iceCream.flavor} , ${iceCream.isVanilla}")
  174. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}") iceCream.isVanilla = true println("${iceCream.flavor} , ${iceCream.isVanilla}") Vanilla , true
  175. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}") iceCream.isVanilla = true println("${iceCream.flavor} , ${iceCream.isVanilla}") Vanilla , true
  176. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}") iceCream.isVanilla = true println("${iceCream.flavor} , ${iceCream.isVanilla}") Vanilla , true
  177. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Chocolate") println("${iceCream.flavor} , ${iceCream.isVanilla}") iceCream.isVanilla = true println("${iceCream.flavor} , ${iceCream.isVanilla}") Vanilla , true
  178. Classes - Getters and Setters class IceCream(var flavor: String =

    "Vanilla", val cone: Boolean = true){ var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } }
  179. Classes class IceCream(var flavor: String = "Vanilla", val cone: Boolean

    = true){ constructor(topping: String): this() { cone = false } }
  180. Classes class IceCream(var flavor: String = "Vanilla", val cone: Boolean

    = true){ constructor(topping: String): this() { cone = false } }
  181. Classes class IceCream(var flavor: String = "Vanilla", val cone: Boolean

    = true){ constructor(topping: String): this() { cone = false } }
  182. Classes class IceCream(var flavor: String = "Vanilla", val cone: Boolean

    = true){ constructor(topping: String): this() { cone = false } }
  183. Classes class IceCream(var flavor: String = "Vanilla", val cone: Boolean

    = true){ constructor(topping: String): this("Chocolate", false) { cone = false } }
  184. Classes class IceCream(var flavor: String = "Vanilla", val cone: Boolean

    = true){ constructor(topping: String): this() { cone = false } }
  185. Classes class IceCream(var flavor: String = "Vanilla", val cone: Boolean

    = true){ constructor(topping: String): this() { cone = false } }
  186. Classes Secondary Constructors: • Calls the primary constructor (this()) •

    Cannot assign val/ var to secondary constructor arguments • Get called last
  187. Classes Secondary Constructors: • Calls the primary constructor (this()) •

    Cannot assign val/ var to secondary constructor arguments • Get called last
  188. Classes Secondary Constructors: • Calls the primary constructor(this()) • Cannot

    assign val/ var to secondary constructor arguments • Get called last
  189. Classes Secondary Constructors: • Calls the primary constructor(this()) • Cannot

    assign val/ var to secondary constructor arguments • Get called last
  190. Classes class IceCream(var flavor: String = "Vanilla", var cone: Boolean

    = true){ constructor(topping: String): this() { cone = false } }
  191. Classes class IceCream(var flavor: String = "Vanilla", var cone: Boolean

    = true){ val cup = !cone constructor(topping: String): this() { cone = false } }
  192. Classes class IceCream(var flavor: String = "Vanilla", var cone: Boolean

    = true){ val cup = !cone constructor(topping: String): this() { cone = false } var base = if(cup) "cup" else "cone" }
  193. Classes class IceCream(var flavor: String = "Vanilla", var cone: Boolean

    = true){ val cup = !cone init {/*do something with ice-cream*/} constructor(topping: String): this() { cone = false } var base = if(cup) "cup" else "cone" }
  194. Classes class IceCream(var flavor: String = "Vanilla", var cone: Boolean

    = true){ val cup = !cone init {/*do something with ice-cream*/} constructor(topping: String): this() { cone = false } init {/*do something with ice-cream*/} var base = if(cup) "cup" else "cone" init {/*do something with ice-cream*/} }
  195. Classes class IceCream(var flavor: String = "Vanilla", var cone: Boolean

    = true){ val cup = !cone init {/*do something with ice-cream*/} constructor(topping: String): this() { cone = false } init {/*do something with ice-cream*/} var base = if(cup) "cup" else "cone" init {/*do something with ice-cream*/} }
  196. Classes class IceCream(var flavor: String = "Vanilla", var cone: Boolean

    = true){ val cup = !cone init {/*do something with ice-cream*/} constructor(topping: String): this() { cone = false } init {/*do something with ice-cream*/} var base = if(cup) "cup" else "cone" init {/*do something with ice-cream*/} }
  197. Classes class IceCream(var flavor: String = "Vanilla", var cone: Boolean

    = true){ val cup = !cone init {/*do something with ice-cream*/} constructor(topping: String): this() { cone = false } init {/*do something with ice-cream*/} var base = if(cup) "cup" else "cone" init {/*do something with ice-cream*/} }
  198. Classes class IceCream(var flavor: String = "Vanilla", var cone: Boolean

    = true){ val cup = !cone init {/*do something with ice-cream*/} constructor(topping: String): this() { cone = false } init {/*do something with ice-cream*/} var base = if(cup) "cup" else "cone" init {/*do something with ice-cream*/} }
  199. Classes class IceCream(var flavor: String = "Vanilla", var cone: Boolean

    = true){ val cup = !cone init {/*do something with ice-cream*/} constructor(topping: String): this() { cone = false } init {/*do something with ice-cream*/} var base = if(cup) "cup" else "cone" init {/*do something with ice-cream*/} }
  200. Classes class IceCream(var flavor: String = "Vanilla", var cone: Boolean

    = true){ val cup = !cone init {/*do something with ice-cream*/} constructor(topping: String): this() { cone = false } init {/*do something with ice-cream*/} var base = if(cup) "cup" else "cone" init {/*do something with ice-cream*/} }
  201. Classes class IceCream(var flavor: String = "Vanilla", var cone: Boolean

    = true){ val cup = !cone init {/*do something with ice-cream*/} constructor(topping: String): this() { cone = false } init {/*do something with ice-cream*/} var base = if(cup) "cup" else "cone" init {/*do something with ice-cream*/} }
  202. Visibility Modifiers • public - declarations are visible everywhere •

    private - visible inside the file/class containing the declaration • internal - visible inside the same module • protected - visible inside the class and its subclasses
  203. Visibility Modifiers • public - declarations are visible everywhere •

    private - visible inside the file/class containing the declaration • internal - visible inside the same module • protected - visible inside the class and its subclasses
  204. Visibility Modifiers • public - declarations are visible everywhere •

    private - visible inside the file/class containing the declaration • internal - visible inside the same module • protected - visible inside the class and its subclasses
  205. Visibility Modifiers • public - declarations are visible everywhere •

    private - visible inside the file/class containing the declaration • internal - visible inside the same module • protected - visible inside the class and its subclasses
  206. Visibility Modifiers class IceCream(var flavor: String = "Vanilla", var cone:

    Boolean = true){ val cup = !cone init {/*do something with ice-cream*/} constructor(topping: String): this(){ cone = false } init {/*do something with ice-cream*/} var base = if(cup) "cup" else "cone" init {/*do something with ice-cream*/} }
  207. Visibility Modifiers class IceCream(var flavor: String = "Vanilla", var cone:

    Boolean = true){ val cup = !cone constructor(topping: String): this(){ cone = false } var base = if(cup) "cup" else "cone" }
  208. Visibility Modifiers class IceCream(var flavor: String = "Vanilla", var cone:

    Boolean = true){ val cup = !cone constructor(topping: String): this(){ cone = false } var base = if(cup) "cup" else "cone" }
  209. Visibility Modifiers class IceCream(var flavor: String = "Vanilla", var cone:

    Boolean = true){ val cup = !cone constructor(topping: String): this(){ cone = false } var base = if(cup) "cup" else "cone" var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } }
  210. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } }
  211. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } }
  212. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } }
  213. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } }
  214. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles")
  215. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles")
  216. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles")
  217. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor
  218. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor
  219. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible
  220. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone
  221. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone
  222. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible
  223. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup
  224. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup
  225. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible
  226. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base
  227. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base
  228. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible
  229. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla
  230. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla
  231. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla
  232. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla
  233. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" protected var isVanilla get() = this.flavor == "Vanilla" set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla
  234. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" var isVanilla protected get() = this.flavor == "Vanilla" protected set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla
  235. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" var isVanilla protected get() = this.flavor == "Vanilla" protected set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla //not visible
  236. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" var isVanilla protected get() = this.flavor == "Vanilla" protected set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla //not visible
  237. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" var isVanilla public get() = this.flavor == "Vanilla" protected set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla //not visible
  238. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" var isVanilla public get() = this.flavor == "Vanilla" protected set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla//visible
  239. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" var isVanilla public get() = this.flavor == "Vanilla" protected set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla//visible iceCream.isVanilla = false
  240. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" var isVanilla public get() = this.flavor == "Vanilla" protected set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla//visible iceCream.isVanilla = false
  241. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" var isVanilla public get() = this.flavor == "Vanilla" protected set(value) { if(value) flavor = "Vanilla" } } val iceCream = IceCream("Sprinkles") iceCream.flavor //visible iceCream.cone //visible iceCream.cup //visible iceCream.base //not visible iceCream.isVanilla//visible iceCream.isVanilla = false //not
  242. Visibility Modifiers internal class IceCream private constructor( public var flavor:

    String = "Vanilla", internal var cone: Boolean = true) { public val cup = !cone internal constructor(topping: String): this(){ cone = false } protected var base = if(cup) "cup" else "cone" var isVanilla public get() = this.flavor == "Vanilla" protected set(value) { if(value) flavor = "Vanilla" } }