Search Header Logo

Kotlin

Authored by Christian Dräger

Computers

KG

Used 119+ times

Kotlin
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

20 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the difference between val and var in Kotlin?

Variables declared with var are final, those with val are not.

Variables declared with val are final, those with var are not.

Variables declared with val can only access const members

var is scoped to the nearest function block and val is scoped to the nearest enclosing block

Answer explanation

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does a data class not offer?

A generated copy(.. .) method, to create copies of instances

Automatic conversion from/to JSON

Auto-generated hashCode() and equals() methods

An auto-generated toString() method

Answer explanation

Data classes are a very handy feature of Kotlin to create classes whose main purpose is to hold data, with the Kotlin compiler automatically creating methods like equals()/hashCode(), toString(), copy(...) and more. Automatic conversion to/from JSON is not (yet) part of this.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of these targets does Kotlin currently not support?

.NET CLR

LLVM

JavaScript

JVM

Answer explanation

Kotlin can currently be compiled to both JVM bytecode, JavaScript and to native code (LLVM). The .NET CLR is not (yet) officially supported.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What are Kotlin coroutines?

These are functions which accept other functions as arguments or return them

They provide asynchronous code without thread blocking

That's how the automatically generated methods hashCode() and equals() in data classes are called

It's Kotlin's term for class methods

Answer explanation

Coroutines are a way to run code asynchronously without the usual thread blocking.

https://kotlinlang.org/docs/reference/coroutines.html

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

What is 'to' in the example below:

An infix extension function creating a Pair(33, 42)

A syntax error

A Kotlin keyword to create a Range from 33 to 42

A Kotlin keyword to create a Pair(33, 42)

Answer explanation

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the correct way to declare a variable of integer type in Kotlin?

int i = 42

var i : int = 42

let i = 42

var i : Int = 42

Answer explanation

Variables in Kotlin are declared with the var (variable) or val (value) keywords, the latter making it final, followed by a : and the type. As Kotlin does not have primitive types, Int is correct while int leads to an error. When also defining a variable as in the example, you may often omit the type and let the compiler infer it. So var i = 42 would be fine, too.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Media Image

Which is true for the following simple class declaration?

It has a private property "name"

It can be extended by other classes

It is public

It is package-private

Answer explanation

Classes in Kotlin are public and final by default. To allow other classes to extend it, the open modifier is used. Declared properties are public by default.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?