Getting familar with implementing Interfaces

Report a typo

We previously used the quite simple Animal interface as an example. Now to get the hang of it, implement the Dog class, which is supposed to implement the Animal interface.

For the purpose of this task, consider the dog being as close to normal as you can imagine. It means that the solutions in which dogs can talk or have a suspiciously large number of limbs will be considered wrong.

fun bark(): String { return barkString }
fun meow(): String { return meowString }
fun speak(): String { return speakString }

fun walk() { /* some code */ }
fun fly() { /* some code */ }
fun swim() { /* some code */ }

interface Animal {
    val numberOfLimbs: Int
    fun move()
    fun communicate(): String
}
Write a program in Kotlin
interface Animal {
val numberOfLimbs: Int
fun move()
fun communicate(): String
}

// Do not change code below.

fun bark(): String { return "bark" }
fun meow(): String { return "meow" }
fun speak(): String { return "speak" }

fun walk() { println("walk") }
fun fly() { println("fly") }
fun swim() { println("swim") }

// Do not change code above.

class Dog : Animal {
override val numberOfLimbs: Int
get() = /* ? */

override fun move() {
/* Your code here */
}

override fun communicate(): String {
/* Your code here */
}
}
___

Create a free account to access the full topic