Last active
August 24, 2018 03:10
-
-
Save mayuroks/0ae120be11a9291b37869b0ca3d1ec6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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