Top 10 Kotlin Interview Questions & Answers for 2020

Here I am providing you very useful kotlin interview questions and answers which will help you to crack the kotlin interview for both fresher and experienced  Developer.

1.What do you mean by Kotlin ?

Kotlin is a statically typed programming language that runs on the JVM and It is completely interoperable with java programming language. 

2.What is the Target Platform of Kotlin ? How is Kotlin-Java interoperability  possible?

JVM (Java virtual platform) is the target platform of Kotlin.Kotlin is 100 % Interoperable with Java because both produce bytecode on compilation.Hence Kotlin code can be called from java and vice-versa.

3.How do you declare variables in kotlin ?How does the declaration different  from the  java counterpart ?

There are two major  differences between java and kotlin variable declaration.

The type of declaration:

The java declaration looks like

String s=”placement preparation”;

Int x=20;

The Kotlin declaration looks like

val s:String=”placement preparation”

var x=20

In kotlin,the declaration begins with val and var followed by optional type.Kotlin can automatically detect the type using type inference.

Default value:

The following  is possible in java

String  s;

The following variable declaration in kotlin is not valid

val  s: String

4.What is the difference between val and var declaration? How to convert String into an Int ?

val variables cannot be changed .They are like final modifiers  in java.A var can re-assigned values that must be of the same data types.

fun main(args:Array<String>)
val s:String=”Hi”
val x=5
x=”6”.toInt( )

We use the toInt( ) method to convert String into Int.

5.What is the difference between == and === operator in kotlin ?

== operator is used to compare whether the values are equal or not.=== operator is used to  compare whether references are equal or not.

6.List down the visibility modifiers in kotlin?What are the default visibility modifiers ?





Public is the default modifiers

7.Does the following inheritance structure compile ?

class A
class B:A( )

By default classes are final in kotlin.To make them non-final you have to add an open modifier.

open class A
class B:A( )

8.What are the types of constructor in Kotlin ?How are they different ?How do you define them in your class ?

There are two types of constructor in kotlin.

1.Primary constructor

2.Secondary constructor

1.Primary constructor

These are defined in the class headers.They cannot hold any logic.There is only one primary constructor per class.

2.Secondary constructor

They are defined in the class body.They must delegate to the primary constructor if it exists.They can hold logic.There can be more than one secondary  constructor.

9.What is the type of following Array ?

The declaration of Array is given below:

val arr=arrayOf(1,2,7)

The type is Array<Int>.That is all for kotlin interview questions and answers.

10.Explain Higher-Order-Function in kotlin?

Higher Order Function:A higher order function is a function that takes functions as parameters,or returns a function.

Thanks and Regards

Placement Preparation

Leave a Comment