Skip to content

Instantly share code, notes, and snippets.

@mayuroks
Last active August 24, 2018 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayuroks/0ae120be11a9291b37869b0ca3d1ec6d to your computer and use it in GitHub Desktop.
Save mayuroks/0ae120be11a9291b37869b0ca3d1ec6d to your computer and use it in GitHub Desktop.
open class Animal { // Parent class
var name: String? = null // Nullable variable
var legs: Int = 0 // Non-nullable variable
lateinit var map: HashMap<Integer, String> // Variable inited later in the code
constructor(legs: Int) {
this.legs = legs
}
constructor(legs: Int, name: String) {
this.legs = legs
this.name = name
}
// open keyword allows the function to be overridden
open fun speak() : String? {
return null
}
}
class Dog : Animal { // Child class
constructor(legs: Int) : super(legs) {
// Optional code block
}
// Just a super call, without additional code block
constructor(legs: Int, name: String) : super(legs, name)
// Function over-ridding
override fun speak(): String? {
return "Bark! Bark!"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment