Created
December 29, 2021 16:26
-
-
Save arsalankhan994/faa6fc6a802dce95bf721e8ae1a70c29 to your computer and use it in GitHub Desktop.
This file contains 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
fun main() { | |
/* | |
using val, to assign value only one time | |
*/ | |
val assignValueOnlyOneTime = "Erselan Khan" | |
assignValueOnlyOneTime = "" | |
/* | |
using var, to assign value multiple times | |
*/ | |
var assignValueMultipleTimes = "Erselan Khan" | |
assignValueMultipleTimes = "Arsalan Khan" | |
/* | |
Accessing method from class object | |
*/ | |
val keywordsKotlin = KeywordsKotlin() | |
keywordsKotlin.objectBoundMethod() | |
/* | |
Accessing method from class | |
*/ | |
KeywordsKotlin.classBoundMethod() | |
/* | |
calling method of singleton class | |
*/ | |
SingletonClass.methodOfSingletonClass() | |
} | |
class KeywordsKotlin { | |
companion object { | |
fun classBoundMethod() { | |
println("This is class bound method") | |
} | |
} | |
fun objectBoundMethod() { | |
println("This is object bound method") | |
} | |
} | |
class ChildClassOne : ExtendableClass() { | |
} | |
/* | |
using open, allows subclassing a class or overriding a member | |
*/ | |
open class ExtendableClass { | |
} | |
class ChildClassTwo : NonExtendableClass() { | |
} | |
/* | |
by default all classes are non-extendable in Kotlin | |
*/ | |
class NonExtendableClass { | |
} | |
/* | |
using object, to make class Singleton | |
*/ | |
object SingletonClass { | |
fun methodOfSingletonClass() { | |
println("This is a method of singleton class") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment