Inheritance and Interfaces
Interfaces
Implement a small interface with a class.
interface
An interface names behavior that a class promises to provide.
Interfaces
Interfaces.kt
Replay: real traced execution (multi-file project)
interface Describable {
fun describe(): String
}
class Task(val title: String) : Describable {
override fun describe(): String {
return "task:$title"
}
}
fun main() {
val title = "Build"
val task = Task(title)
val description = task.describe()
println("title=$title")
println("description=$description")
}
interface Describable {
fun describe(): String
}
class Task(val title: String) : Describable {
override fun describe(): String {
return "task:$title"
}
}
fun main() {
val title = "Test"
val task = Task(title)
val description = task.describe()
println("title=$title")
println("description=$description")
}
interface Describable {
fun describe(): String
}
class Task(val title: String) : Describable {
override fun describe(): String {
return "task:$title"
}
}
fun main() {
val title = "Ship"
val task = Task(title)
val description = task.describe()
println("title=$title")
println("description=$description")
}
title ← Build
11fun main() {12 val title→ Build = "Build" //@title="Test", "Ship"13 val task = Task(titleBuild)14 val description = task.describe()override fun describe(): String
5class Task(val title: String) : Describable {6 override fun describe(): String {7 return "task:$titleBuild"8 }description ← task:Build
13 val task = Task(title)14 val description→ task:Build = task.describe()1516 println("title=$titleBuild")17 println("description=$descriptiontask:Build")18}outputtitle=Build description=task:Build
title ← Test
11fun main() {12 val title→ Test = "Test"13 val task = Task(titleTest)14 val description = task.describe()override fun describe(): String
5class Task(val title: String) : Describable {6 override fun describe(): String {7 return "task:$titleTest"8 }description ← task:Test
13 val task = Task(title)14 val description→ task:Test = task.describe()1516 println("title=$titleTest")17 println("description=$descriptiontask:Test")18}outputtitle=Test description=task:Test
title ← Ship
11fun main() {12 val title→ Ship = "Ship"13 val task = Task(titleShip)14 val description = task.describe()override fun describe(): String
5class Task(val title: String) : Describable {6 override fun describe(): String {7 return "task:$titleShip"8 }description ← task:Ship
13 val task = Task(title)14 val description→ task:Ship = task.describe()1516 println("title=$titleShip")17 println("description=$descriptiontask:Ship")18}outputtitle=Ship description=task:Ship