Assessments

Chapter 1, Getting Started with Kotlin

Question 1

What's the difference between var and val in Kotlin?

Answer

The val keyword declares an immutable value that cannot be modified once assigned. The var keyword declares a mutable variable that can be assigned multiple times.

Question 2

How do you extend a class in Kotlin?

Answer

To extend a class, you can specify its name and constructor after a semicolon. If it's a regular class, it must be declared open for your code to be able to extend it.

Question 3

How do you add functionality to a final class?

Answer

To add functionality to a class that we cannot inherit from, we can use an extension function. The extension function will have access only to the class itself and to its public ...

Get Kotlin Design Patterns and Best Practices - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.