Junior — Middle
What elements or constructs are prohibited inside an interface?
sobes.tech AI
Answer from AI
In Kotlin interfaces, it is forbidden to declare:
- Fields with state (variables that store values). In interfaces, you can only declare properties without implementation or with a getter/setter without state.
- Constructors (including primary and secondary).
- Initializers (init blocks).
In interfaces, you can declare:
- Abstract methods and properties (without implementation).
- Methods with implementation (default methods).
Example:
interface MyInterface {
val property: String // property without state
fun doSomething() // abstract method
fun defaultMethod() { // method with implementation
println("Default implementation")
}
}