Advanced Kotlin Class Features

May 22 2024 · Kotlin 1.9, Android 14, Android Studio Hedgehog

Lesson 06: Leverage Enum Classes

Demo

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Open your internet browser and search for Kotlin Playground. You’ll see different websites. Select the one provided by the Android Developers page. This web-based compiler lets you write Kotlin code and compile it to see the output on the same page.

enum class FruitType {
  APPLE,
  BANANA,
  ORANGE,
  GRAPE
}
class FruitBox(
  val firstItem: String,
  val secondItem: String,
  val numOfItems: Int,
  val totalCost: Double,
  val fruitType: FruitType
)
fun printContents() {
  println("FruitBox contents: First Item = $firstItem, Second Item = $secondItem")
  println("Total Items = $numOfItems, Total Cost = $$totalCost")
  println("Fruit Type: $fruitType")
}
val appleBananaBox = FruitBox("Apple", "Banana", 5, 10.5, FruitType.APPLE)
  appleBananaBox.printContents()
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction Next: Conclusion