NEW
Font size
WorksheetsLESSON 1-3
Total questions: 60
Worksheet time: 30mins
What is the entry point function of a Kotlin application?
run()
start()
main()
init()
Which function is used to print a line to the standard output?
println()
console.log()
System.out.print()
printLine()
Which keyword declares a read-only (immutable) variable?
static
const
val
var
Which keyword declares a mutable variable that can be changed?
mut
var
let
val
What is the type of the result of 'val x = 5' due to type inference?
Double
Int
String
Float
Which data type represents a value that is either true or false?
Logic
Bit
YesNo
Boolean
How do you insert a variable 'name' directly into a string literal?
"Hello " + name
"Hello $name"
String.format("Hello %s", name)
"Hello {name}"
In Kotlin, 'if' is an expression, which means it returns a value.
False
True
Only in loops
Only for booleans
What is the replacement for the switch statement in Kotlin?
match
case
when
switch
Which collection type cannot be modified after creation?
ArrayList
MutableList
LinkedList
List
Which function creates an array in Kotlin?
Array[]
arrayOf()
list[]
new Array()
What syntax denotes a nullable String type?
String
Optional
Nullable
String?
Which operator allows safely accessing a property of a nullable variable?
->
?.
.
!!
What does the '!!' operator do?
Checks for null safely
Defaults to null
Asserts value is non-null or throws exception
Converts to Int
What is the '?:' operator called?
Elvis operator
Elvis Presley parameter
Safe call operator
Range operator
What tool allows you to run Kotlin code interactively line-by-line?
Compiler
REPL
Debugger
Gradle
On which machine does Kotlin code primarily run in Android?
LLVM
V8
JVM
CLR
Which keyword is used to define a function?
def
method
fun
function
How are function parameters defined in Kotlin?
let name
name: Type
var name
Type name
What symbol indicates a single-line comment?
//
/*
–
#
What return type indicates a function does not return a useful value?
Null
Unit
Void
Nothing
In 'fun main(args: Array
Command-line arguments
Environment variables
System properties
Function defaults
What feature allows calling 'foo(speed=10)' explicitly naming the parameter?
Labels
Tagging
Default arguments
Named arguments
If a function is defined 'fun drive(speed: Int = 50)', what is 50?
Minimum value
Maximum value
Return value
Default value
Can you mix default and required parameters in a function call?
Only if required come last
Only in constructors
Yes
No
How can 'fun double(x: Int): Int { return x * 2 }' be written more concisely?
fun double(x: Int) = x * 2
val double = x * 2
fun double(x: Int) => x * 2
fun double(x) { x * 2 }
What is an expression that makes a function with no name?
Interface
Lambda
Class
Method
What do we call functions that take other functions as parameters?
Constructors
Super functions
Native functions
Higher-order functions
What is the type syntax for a function taking Int and returning Int?
Int : Int
(Int) -> Int
Int produces Int
Function
What is the implicit name for a single parameter in a lambda?
it
this
arg
that
Which list operation returns elements matching a condition?
reduce
sort
filter
map
Which evaluation strategy do Sequences use?
Urgent
Eager
Lazy
Static
Which list operation transforms every item?
map
find
filter
each
What function converts nested collections into a single list?
merge()
flatten()
combine()
flat()
Which operator passes a named function as a reference?
.
->
::
!!
If a lambda is the last argument, where can it be placed?
Outside the parentheses
It cannot be moved
Before the function name
Inside quotes
What method returns the string representation of an object?
string()
toString()
print()
repr()
Which scope level allows a function to be defined inside another function?
Abstract
Global
Local
Member
Which function returns a new list sorted in ascending order?
sorted()
arrange()
order()
sort()
Which function iterates over every element in a collection?
loop
iterate
next
forEach
Which keyword is used to declare a class?
class
type
struct
object
Can classes have properties declared with 'val' and 'var'?
No
Yes
Only var
Only val
Where is the primary constructor defined?
In a separate file
In the class header
Inside the class body
It is optional
Which block is used for initialization code?
start
init
create
constructor
Which keyword defines an additional (secondary) constructor?
constructor
build
init
new
Which keyword refers to the current instance of the class?
it
self
this
me
What is the default visibility modifier in Kotlin?
private
public
protected
internal
What functions are automatically generated for properties?
clone
Getters and Setters
toString
equals
Which keyword allows a class to be subclassed?
open
public
final
static
In Kotlin, classes are 'final' by default. What does this mean?
They cannot be subclassed
They cannot be instantiated
They are immutable
They are static
Which keyword is used to override a method in a subclass?
override
super
new
overwrite
Which type of class cannot be instantiated directly?
data class
abstract class
final class
open class
What defines a contract that classes must implement?
Interface
Abstract class
Module
Header
How does a class implement an interface 'Shape'?
Shape
inherits Shape
implements Shape
extends Shape
Which keyword marks a class aimed primarily at holding data?
value
data
record
struct
Which method is NOT automatically generated for a data class?
copy()
equals()
random()
hashCode()
Which class stores exactly two values?
Double
Pair
Tuple
Two
Which keyword declares an enumeration?
option
list
choice
enum
Which keyword creates a Singleton?
static
instance
object
single
What object inside a class allows static-like member access?
Companion object
Global object
Static block
Shared object
