Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Kotlin has been growing in popularity among developers for some time. It was given even more recognition when Google announced in 2019 that Kotlin was now their preferred language for Android development.
In this comprehensive course, you’ll start by learning the fundamentals, such as: how Java and Kotlin differ, how to work with functions, and how to utilize collections, something you’ll work with extensively in Kotlin.
In the latter half of the course, you’ll be introduced to more advanced concepts like lambdas, fluency in Kotlin, and asynchronous programming. In the last section of the course, you’ll take what you’ve learned and build out an Android application that talks to a backend service.
By the time you’re done with this course, you’ll have a thorough mastery of this modern JVM language. This course is based on the PragProg book, Programming Kotlin, written by the extraordinary, experienced programming-language enthusiast: Venkat Subramaniam.
Q1. To define a mutable variable, we’ll use what?
Q2. Will an error be generated by the following code snippet?
var a = 2
a = a + 1
Q1. What will be the output of the following code snippet?
val factor = 2
fun doubleIt(n: Int) = n * factor
val message = "The factor is $factor"
factor = 0
println(doubleIt(2))
println(message)
0
The factor is 2
4
The factor is 0
Q1. What will be the output of the following code snippet?
fun createMemoFor(name: String): String {
if (name == "User") {
val memo = """Dear $name,
|Hope you are enjoying the course.
|Have a good day $name..."""
return memo
}
return ""
}
println(createMemoFor("User").trimMargin())
Dear User,
Hope you are enjoying the course.
Have a good day User...
Dear User,
Hope you are enjoying the course.
Have a good day User...
Q1. Which error will the following code snippet generate?
fun func() = 2
val message: String = func()
Q2. Which is a valid function signature in Kotlin?
fun func(name: String): String = "$text"
fun func(numbers: IntArray): Int {}
fun func() = "someText"
Q3. Which keyword in kotlin is equivilant to void
in java?
Kotlin.Unit
Unit
Unit.Kotlin
Q1. What will be the output of the following code snippet?
fun test(num:Int= 1, letter: Char ='A'): String = "number is $num and letter is $letter"
println(test(2, 'B'))
number is 1 and letter is A
number is 2 and letter is B
Q1. What is varag
used for?
Q2. How can we annotate a non-trailing parameter with varag
?
Q3. Which of the following is the spread operator symbol?
*
~
@
Q1. What is the ouput of the following code snippet?
fun getFullName() = Triple("a", "b", "c")
val (last) = getFullName()
println("$last")
Q2. Which operator is used to skip values during destructuring?
~
-
_
Q1. What will be the output of the following code snippet?
val compiler: ClosedRange<String> = "kotlic".."kotlin"
println(compiler.contains("kotlinc"))
println(compiler.contains("kotlin"))
true
true
true
false
false
true
Q2. What will be the output of the following code snippet?
for (letter in "a".."e") { print("$letter, ") }
Q1. when
is equivalant to which command?
Q2. Which keyword is used to check a list of objects?
has
in
is
Q3. What will be the output of the following code?
age = 20
when (age) {
in 0..12 -> println("Child")
in 13..19 -> println("Teenager")
else -> println("Adult")
}
Q1. Which Kotlin function can be used to get both index and value from a collection?
forEach
withIndex
listOf
IndexedValue
Q1. How do you create and access arrays in Kotlin?
val score = arrayOf(5, 4, 3, 2, 1)
println(score(2))
val score = arrayOf(5, 4, 3, 2, 1)
println(score[2])
val score = array(5, 4, 3, 2, 1)
println(score[2])
Q2. What is the output of the following code snippet?
println(Array(5) { i -> (i + 1) * (i + 1) }.count())
Q1. Which type of list should be preferred?
Q2. Which of the following commands creates an immutable list?
ImutableListOf(...)
listOf()
readOf()
Q1. Which of the following functions checks for the key in a Map
collection?
contains
containsValue
containsKey
Q2. How would you correctly initialize an immutable Map
?
val letters = mapOf("a" to "b",
"c" to "d")
val letters = mapOf("a" -> "b",
"c" -> "d")
val letters = mapOf("a" in "b",
"c" in "d")
Q1. True or false: non-nullable reference types accept null
as a return from functions.
Q2. The safe call operator checks for what?
Q3. What will the output of the following code snippet be?
fun nickName(name: String?): String {
if (name == "William") {
return "Bill"
}
return null
}
println("Nickname for null is ${nickName(null)}")
Nickname for null is null
Nickname for null is Bill
Q1. Which of the following functions check for the type at runtime?
contains()
equals()
max()
add()
Q2. The is
operator returns false
for which of the following reference types?
Any
&&
null
Q3. What will be the output of the following code snippet?
class Animal {
override operator fun equals(other: Any) = other is Animal
}
val greet: Any = "hello"
val odie: Any = "world"
val toto: Any = Animal()
println(odie == greet)
println(odie == toto)
true
true
false
false
true
false
Q1. Which of the folowing depicts type invariance?
Person
and Teacher
, where Teacher
extends Person
Array<Person>
and Array<Teacher>
, where Teacher
extends Person
Array<Person>
and List<Teacher>
, where Teacher
extends Person
Q2. Which statement best describes covariance?
Q3. The following function would generate an error. Why?
fun <T> test(num: T) {
num.close()
}
close()
methodclose()
method hasn’t been implemented yet*
should have been used instead of T
Q1. Which other keyword has to be used with reified
to make it work?
Class
inline
extends
Q1. What is the correct syntax to declare a singleton object in Kotlin?
object test {
someCode()
}
@Singleton
object test {
someCode()
}
test object {
someCode()
}
Q2. Objects can be used to implement interfaces.
Q3. If functions are closely related to each other, how should they be grouped?
Q1. What type of constructor is shown in the following code snippet?
constructor(
first: String, second: String, third: String): this(first, second, true) {
// code...
}
Q2. Which class gets transformed into a primitive type at runtime?
Q3. Which variable exhibits the read-write property in the following initialization of a class?
class Person(val var1: Int, var var2: String)
Q1. Which of the of following options correctly builds an abstract class?
Q2. A class can be extended from how many abstract classes?
Q3. How can multiple inheritance be used in Kotlin?
Q1. Which classes in Kotlin support inheritance?
open
final
open
and override
Q1. When should delegation be used?
Q2. Which classes are placed around the by
operator to implement delegation?
Q1. Why do collisions occur in a delegating class?
Q2. How do you deal with a collision in the delegating class?
override
override
override
Q1. Access of which two functions is delegated to the properties and variables?
add()
and remove()
getValue
and setValue
kill()
and exec()
Q1. What is the function of the observable delegate?
Q2. What is the function of vetoable delegates?
Q1. Which of the following statements is true?
Q2. Why are anonymous functions used?
Q1. Can the following lambda be considered a closure?
val value = 2
val doubleIt = { i: Int -> i * 2 }
Q1. Why is return
not allowed by default in lambdas?
return
return
Q2. Which statement does the labeled return in lambdas behave like?
break
continue
switch
Q1. What is the flatten
function used for?
Q2. Which functions make up the functional pipeline?
flatten()
and flatmap()
filter()
, map()
, and reduce()
filter()
, map()
, and first()
Q3. Which statement is true for the map()
function?
Q1. What is the correct syntax to overload an operator with two operands?
operator fun plus(other: className) =
className(var1 + other.var2)
plus fun operator(other: className) =
className(var1 + other.var2)
operator fun plus(other: className) =
className(other.var1 + other.var2)
Q2. The operator []
corresponds to which specialized method name?
plus
and minus
get
and set
inc
and dec
Q1. What is a drawback of using recursion?
Q1. Can the tailrec
optimization be used for any recursive problem?
Q1. How does memoization work?
Q1. You are working on your laptop while waiting in line to get your passport. This is an example of concurrency.
I hope this The Ultimate Guide to Kotlin Programming Educative Quiz Answers would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>