Kotlin Interview Questions

Kotlin: Prepare Kotlin Interview Questions, Answers, Tips, news, tutorials. Find Kotlin Questions asked in various companies, Get Career advice & Interview Procedures from Kotlin experts.

  • What is the difference between object { } block and companion object { } code block in Kotlin?

    Posted By: Pearl

  • What is the lateinit modifier used for?

    Posted By: Ajay

    lateinit modifier in Kotlin is used to delay the initialization of a variable.

    The requirement of using lateinit modifier

    • These variables must be declared using var keyword, val is not allowed.
    • Must be either a property inside the body of a class or a top-level property
    • Can only be of non-null type
    • Primitive types disallowed

    Declaration Syntax

    lateinit var myVar: MyObject

  • What is Elvis Expression in Kotlin?

    Posted By: Carlos

    The Elvis operator in Kotlin is an operator that receives two inputs and returns the first argument if it is non-null or the second one otherwise. It is fancily called the null-coalescing operator. It is a variant of the ternary operator but for null-safety checking.


    x ?: y // yields `x` if `x` is not null, `y` otherwise.

  • For what vararg keyword in Kotlin used for?

    Posted By: Woodie

  • What are High Level Functions in Kotlin?

    Posted By: FedorNob

  • What are Coroutines?

    Posted By: PashkevichAcem

    Coroutines are light weight thread in Kotlin that convert async callbacks for long-running tasks, such as database or network access, into sequential code.

    Defining a simple Coroutine

    coroutine {
        progress.visibility = View.VISIBLE
        val user = suspended { userService.doLogin(username, password) }
        val currentFriends = suspended { userService.requestCurrentFriends(user) }
        val finalUser = user.copy(friends = currentFriends)
        toast("User ${finalUser.name} has ${finalUser.friends.size} friends")
        progress.visibility = View.GONE

    Above is comman structure for a coroutine that have have a coroutine builder, and a set of suspending functions that will suspend the execution of the coroutine until they have the result.

  • What is diffrence between Val and Var?

    Posted By: Arlington

  • What are different types of constructors available in Kotlin?

    Posted By: Darwin

  • Why is Kotlin preferred over Java?

    Posted By: KevinViali

  • Explain Kotlin's Null safety?

    Posted By: Lokesh Ekbote

  • What it the main the difference between lazy and lateinit in Kotlin?

    Posted By: ramesh

  • How to define Constant in Kotlin.

    Posted By: Ali Hyder

    Val keyword is used to define a Constant in Kotlin.

    Syntax for defining a Local Constant in Kotlin.

    val firstName: String = "Chike"

    Creating a public constant in Kotlin like Java public static final

    companion object{
         const val MY_CONSTANT = "Constants"

  • What is difference between inline and infix functions in Kotlin?

    Posted By: Dallas

  • What is suspend in Kotlin?

    Posted By: Sharad Jaiswal

    Suspend is a function in Kotlin Coroutines. A suspending function is simply a function that can be paused and resumed at a later time. They can execute a long-running operation and wait for it to complete without blocking.

  • How to create AsyncTask in Android with Kotlin ?

    Posted By: Sharad Jaiswal

  • Explain Launch vs Async in Kotlin ?

    Posted By: Sharad Jaiswal

  • ;