Preparation for Kotlin Interview Test

Why a developer can prefer Kotlin over Java?

Answer:-

Because Kotlin has several features which even modern versions of Java lack.

Let’s list down few of them.

  • Kotlin support best features of functional programming and OO programming language.
  • Kotlin handles Null Pointer Exceptions easily.
  • Kotlin support lambdas, higher order functions, smart casting.
  • Approximately 40 % less number of code lines as compared to Java.

Reference:-

Kotlin comparison to Java

Can kotlin code be executed without JVM?

Answer :-

Yes this is feature of Kotlin / Native which is under development. It compile Kotlin code into native code which can be executed without JVM.

What ara Data classes in Kotlin and how they can be compared with POJO?

Answer:-

Creating Data Classes in Kotlin (DTO / POJO) example

What is Kotlin String Interpolation ?

Answer:-

String Templates in Kotlin can be evaluated (interpolated).

Reference:-

String Interpolation and String Templates in Kotlin example

How do you define Singleton Object in Kotlin ?

We can use companion object in Kotlin to declare a class Singleton.

Kotlin companion object also solve problem of static member and static functions, because any property inside companion object can be called without creating instance of class.

Example:-

class AppClass : Application() {
    companion object {
        var instance: AppClass
}
    override fun onCreate() {
        super.onCreate()
        instance = this
    }
}

How Kotlin handle Null Pointer Exceptions ?

Reference:-

https://kotlinlang.org/docs/reference/null-safety.html

What are three structural expressions in Kotlin ?

Answer:-

What are different Types of Constructors in Kotlin, explain them.

Answer:-

There are two different types of constructors in Kotlin.

  • Primary constructor
  • Secondary constructor

Primary constructor is part of class header and is declared after class name.

Secondary constructor is declared inside class body.

Class can have one or more Secondary constructor.

What is equivalent of Switch Statement in Java in Kotlin ?

Answer:-

In Kotlin when is alternate of Switch statement.

Example:-

when (x) { is Foo -> ...  (true if x is of type Foo)
 is Bar -> ...  (true if x is of type Bar)
 else -> ...    (true if none of the above condition is met)
}

Reference:-

Instance checks or Type checking in Kotlin example

Can when statement in Kotlin be used without passing any argument ?

Answer:-

Yes, in that case each branch of when statement will work as if else if.

If any branch fulfills its condition its body will be executed.

Does Kotlin support Checked Exceptions like in Java ?  if yes give an example.

Answer:-

No, Kotlin does not support Checked Exceptions.

What is Elvis Expression in Kotlin ?

What is Kotlin/Native Multiplatform project?

Answer:-

Reference:-

Kotlin Native iOS Development using Multiplatform Project

What are primitive Data Types in kotlin ?

Answer:-

Kotlin does not support primitive Data Types like in Java.

What are open, final and abstract Modifiers in Kotlin ?

Answer:-

Open, final and abstract modifiers in Kotlin

Can we pass different number of arguments to same Function in Kotlin ?

Answer:-

Yes.

What are inline functions in Kotlin ?

 

How to declare mutable and immutable Objects in Kotlin ?

Answer:-

We use var and val keywords to declare any property mutable or immutable in Kotlin.

The post Top Kotlin Interview Questions and Answers appeared first on Welcome to Developine.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 401 other subscribers