FlashKeepers

Kotlin · College · College and University

Kotlin III: Classes and OOP

Kotlin classes, data classes, sealed classes, objects, companion objects, interfaces, delegation and extension functions.

About this set

39 basic cards for College Kotlin. Set 3 of 4 in Kotlin. It opens with "What is the primary purpose of a data class in Kotlin?" and "How do you declare a data class in Kotlin?". Study it alongside the other College sets below.

39 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is the primary purpose of a data class in Kotlin?
Show answerTo hold data with automatically generated equals(), hashCode(), toString(), copy() and componentN() functions
How do you declare a data class in Kotlin?
Show answerdata class ClassName(val prop1: Type1, val prop2: Type2)
What does the copy() function do on a data class?
Show answerCreates a shallow copy of the object, allowing you to modify specific properties in the new instance
What is a sealed class in Kotlin?
Show answerA class that restricts which subclasses can inherit from it; all subclasses must be defined in the same file or nested
Why use a sealed class instead of an abstract class?
Show answerSealed classes provide exhaustive when expression checking, ensuring all subclass types are handled
How do you declare a singleton object in Kotlin?
Show answerobject SingletonName { ... }
What is the difference between object and class in Kotlin?
Show answerobject declares a singleton instance; class declares a template for creating multiple instances
What is a companion object in Kotlin?
Show answerAn object declared inside a class that can access private members and holds static-like properties and methods
How do you call a companion object member?
Show answerClassName.memberName (no instance needed, like static members in Java)
Can a class have more than one companion object?
Show answerNo, a class can have at most one companion object
How do you declare an interface in Kotlin?
Show answerinterface InterfaceName { fun method(): ReturnType; val property: Type }
Can Kotlin interfaces have properties?
Show answerYes, interfaces can have abstract properties and properties with default implementations
What is delegation in Kotlin?
Show answerA design pattern where an object forwards method calls to another object, using the by keyword
How do you implement delegation in Kotlin?
Show answerclass Derived(val base: Base) : Base by base { ... }
What is an extension function in Kotlin?
Show answerA function added to an existing class without inheritance or modification, using receiver.method() syntax

24 more cards in the app

Study this set free