- How do you define a class in Kotlin?
- Use the class keyword followed by a name. You can then optionally add properties and methods.
- How do you define an interface in Kotlin?
- Use the interface keyword followed by a name. You can then optionally add properties and functions.
- What are data classes?
- Special classes that generate the equals(), hashCode(), and toString() implementations, and are ideal for immutable data classes
- What are sealed classes?
- A special type of class useful for creating restricted class hierarchies. They are similar to enums, but allow each type in the hierarchy to have unique properties and methods.
- How is a sealed class different from an enum?
- Sealed classes can include multiple different classes within the hierarchy and can include different data and methods.
- What is an object expression?
- Kotlin's way of implementing anonymous classes
- What is an object declaration?
- A native way of supporting the Singleton pattern
- What is a companion object?
- An object declaration that is scoped to a specific class instance
- What are the four visibility modifiers in Kotlin?
- Public
- Private
- Internal
- Protected
- What are the differences between a primary and secondary constructor?
- There can only be one primary constructor.
- Primary constructors can define properties.
- There can be multiple secondary constructors.
- Primary constructor initialization happens before anything else.