Skip to content

Instantly share code, notes, and snippets.

@msomu
Last active May 19, 2020 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msomu/dcd482df2d4f5b1951cf20bf992cc598 to your computer and use it in GitHub Desktop.
Save msomu/dcd482df2d4f5b1951cf20bf992cc598 to your computer and use it in GitHub Desktop.
Kotlin Job Interview Questions sample 3 Questions

Question 1 (Easy)

How do you make Kotlin variables nullable by default?
A) Use it same like Java
B) Use !! to make variables nullable
C) Use $ to make variables nullable
D) Use ? to make variables nullable

Answer :

D) Use ? to make variables nullable

Explanation :

Kotlin variables are not nullable by default.
Use ? to make variables nullable. Example :

var marbles: Int? = null

Question 2 (Medium)

Which one of these extension functions on
class ForestTrees( val color: String, val size: Int, private val cost: Double, val leafy: Boolean) will give a compiler error?

A) fun ForestTrees.isRed() = color == "red"

B) fun ForestTrees.isBig() = size > 45

C) fun ForestTrees.isExpensive() = cost > 10.00

D) fun ForestTrees.isNotLeafy() = leafy == false

Answer :

C) fun ForestTrees.isExpensive() = cost > 10.00

Explanation :

Since the cost is marked private You will get this error message
⇒ error: cannot access 'cost': it is private in 'ForestTrees'

Question 3 (Hard)

Difference between List<*> and List<Any>
A) List<*> and List<Any> both will accept only one type
B) List<*> will accept only one type, List<Any>will accept any number of types
C) List<Any>will accept only one type, List<*>will accept any number of types
D) List<*> and List<Any> both will accept any number of types

Answer :

B) List<*> will accept only one type, List<Any>will accept any number of types

Explanation :

List<*> can contain objects of any type, but only that type, so it can contain Strings (but only Strings)
while List<Any> can contain Strings and Integers and whatnot, all in the same list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment