0
0
Kotlinprogramming~10 mins

Interface declaration and implementation in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an interface named 'Drivable'.

Kotlin
interface [1] {
    fun drive()
}
Drag options to blanks, or click blank then click option'
ADrivable
BCar
CDriveable
DVehicle
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name instead of an interface name.
Misspelling the interface name.
2fill in blank
medium

Complete the code to implement the 'Drivable' interface in the 'Car' class.

Kotlin
class Car : [1] {
    override fun drive() {
        println("Driving the car")
    }
}
Drag options to blanks, or click blank then click option'
ADrivable
BRunnable
CVehicle
DDriveable
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong interface name.
Forgetting to override the 'drive' method.
3fill in blank
hard

Fix the error in the code by completing the interface method declaration correctly.

Kotlin
interface Drivable {
    fun [1]()
}
Drag options to blanks, or click blank then click option'
ADrive
Bdrive
Cdriving
Ddrives
Attempts:
3 left
💡 Hint
Common Mistakes
Capitalizing the method name incorrectly.
Using a different method name than in the class.
4fill in blank
hard

Fill both blanks to declare an interface and implement it in a class.

Kotlin
interface [1] {
    fun start()
}

class Motorcycle : [2] {
    override fun start() {
        println("Motorcycle started")
    }
}
Drag options to blanks, or click blank then click option'
AStartable
BRunnable
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for interface and implementation.
Confusing interface names with class names.
5fill in blank
hard

Fill all three blanks to create an interface with two methods and implement it in a class.

Kotlin
interface [1] {
    fun start()
    fun stop()
}

class Bicycle : [2] {
    override fun start() {
        println("Bicycle started")
    }
    override fun [3]() {
        println("Bicycle stopped")
    }
}
Drag options to blanks, or click blank then click option'
AOperable
Cstop
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names in override.
Mismatch between interface and class names.