Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a class that implements two interfaces.
Kotlin
interface A {
fun foo()
}
interface B {
fun bar()
}
class MyClass : [1] {
override fun foo() {
println("foo")
}
override fun bar() {
println("bar")
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&' or '|' instead of ',' to separate interfaces
Not separating interfaces at all
✗ Incorrect
In Kotlin, to implement multiple interfaces, separate them with commas.
2fill in blank
mediumComplete the code to override the method from interface A.
Kotlin
interface A {
fun greet(): String
}
class Person : A {
override fun [1](): String {
return "Hello"
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different method name than declared in the interface
Forgetting to override the method
✗ Incorrect
The method name must match exactly the one declared in the interface.
3fill in blank
hardFix the error in the class declaration to implement both interfaces A and B.
Kotlin
interface A {
fun foo()
}
interface B {
fun bar()
}
class Sample : [1] {
override fun foo() {}
override fun bar() {}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces or symbols like '&' or '|' instead of commas
Not separating interfaces
✗ Incorrect
Interfaces must be separated by commas in Kotlin class declarations.
4fill in blank
hardFill both blanks to complete the class declaration and method override.
Kotlin
interface X {
fun action()
}
interface Y {
fun action()
}
class Combined : [1] {
override fun [2]() {
println("Action performed")
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&' instead of ',' to separate interfaces
Using wrong method name in override
✗ Incorrect
Separate interfaces with commas and override the method named 'action'.
5fill in blank
hardFill all three blanks to implement two interfaces and override their methods correctly.
Kotlin
interface First {
fun firstMethod()
}
interface Second {
fun secondMethod()
}
class MultiImpl : [1] {
override fun [2]() {
println("First method")
}
override fun [3]() {
println("Second method")
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '&' instead of ',' to separate interfaces
Incorrect method names in overrides
✗ Incorrect
Separate interfaces with commas and override both methods with their exact names.