Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
fun main(args: Array<String>) {
println(MyFunction("tutorialsPoint.com"))
}
fun MyFunction(x: String): String {
var c:String ="Hey!! Welcome To ---"
return (c+x)
}
import kotlin.properties.Delegates
class User {
var name: String by Delegates.observable("Welcome to Tutorialspoint.com") {
prop, old, new ->
println("$old -> $new")
}
}
fun main(args: Array<String>) {
val user = User()
user.name = "first"
user.name = "second"
}
interface Base {
fun printMe() //abstract method
}
class BaseImpl(val x: Int) : Base {
override fun printMe() { println(x) } //implementation of the method
}
class Derived(b: Base) : Base by b // delegating the public method on the object b
fun main(args: Array<String>) {
val b = BaseImpl(10)
Derived(b).printMe() // prints 10 :: accessing the printMe() method
}
fun main(args: Array<String>) {
var objet=genericsExample<String>("JAVA")
var objet1=genericsExample<Int>(10)
}
class genericsExample<T>(input:T){
init{
println("I am getting called with the value "+input)
}
}
sealed class MyExample {
class OP1 : MyExample() // MyExmaple class can be of two types only
class OP2 : MyExample()
}
fun main(args: Array<String>) {
val obj: MyExample = MyExample.OP2()
val output = when (obj) { // defining the object of the class depending on the inuputs
is MyExample.OP1 -> "Option One has been chosen"
is MyExample.OP2 -> "option Two has been chosen"
}
println(output)
}
fun main(args: Array<String>) {
val book: Book = Book("Kotlin", "TutorialPoint.com", 5)
println("Name of the Book is--"+book.name) // "Kotlin"
println("Puclisher Name--"+book.publisher) // "TutorialPoint.com"
println("Review of the book is--"+book.reviewScore) // 5
book.reviewScore = 7
println("Printing all the info all together--"+book.toString()) //using inbuilt function of the data class
println("Example of the HasCode function--"+book.hashCode())
}
data class Book(val name: String, val publisher: String, var reviewScore: Int)
fun main(args: Array<String>) {
println("Heyyy!!!"+A.show())
}
class A{
companion object{
fun show():String{
return("You are learning Kotlin from TutorialsPoint.com")
}
}
}