Skip to content

Commit

Permalink
added objectoriented ExtensionProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
poncoe committed Sep 1, 2019
1 parent 2013765 commit e831069
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/objectoriented/ExtensionProperties.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package objectoriented

/*
Extension properties dilakukan di luar kelas. Dengan demikian,
Extension properties hanya bisa didefinisikan dengan cara menyediakan getter dan/atau setter secara eksplisit.
Kita dapat menambahkan sebuah properti tanpa harus membuat sebuah kelas yang mewarisi kelas tersebut.
*/

class AnimalExtProperties(var name: String, var weight: Double, var age: Int, var isMammal: Boolean)

val AnimalExtProperties.getAnimalInfo : String
get() = "Nama: ${this.name}, Berat: ${this.weight}, Umur: ${this.age} Mamalia: ${this.isMammal}"

fun main() {
val meonk = AnimalExtProperties("Meonk", 5.0, 2, true)
println(meonk.getAnimalInfo)
}

0 comments on commit e831069

Please sign in to comment.