Top 20 Kotlin Interview Questions & Answers for 2020

Hello I am providing you Top 20 kotlin interview questions & Answers that will help you to crack Android with kotlin interviews for both fresher and experienced developers.

1.What is kotlin ?

Kotlin is an open source  and statically-type programming language which runs on JVM(Java Virtual machine).

2.Which company has developed Kotlin language ?

JetBrains company has developed the kotlin language but later acquired this  “language”  by Google & launched officially for android development.

3. What are the main features of kotlin that java doesn’t support ?

There are main features of kotlin that java doesn’t support given below:

1.Operator overloading

2.Companion objects

3.Null safety

4.Range expressions

5.Coroutines

6.Smart casts

4. What is  Extension function ?

Extension function is used to extend a  class  with new functionality without inherit from the class

5.What are the programming types that kotlin support ?

There are two types of programing types that kotlin support

1.oops(Object -oriented programming system)

2.Procedural programming

6.What are the access modifiers available in kotlin.What is the default access modifier ?

There are four visibility modifiers available in kotlin

1.Internal

2.public

3.Protected

4.private

“Public “ is the default  access modifier

7.What are the types constructores in kotlin .How are they different & How do you define them in class ?

There are two types of constructor.

1.Primary constructor

It is defined in the class header & does not contain any logic.There is only one primary constructor per class

2.Secondary constructor

It is defined in the class body & contains logic.There can be two or more constructor per class.

8.What is the difference between the inline & infix  functions ?

Inline functions

Inline functions are used to save us memory overhead by preventing object allocations.

Infix functions

Infix functions are used to call functions without parentheses or brackets

9.What is the difference between lazy and lateinit ?

Both are used to delay the property initialization in kotlin

lazy is a method or lambda expression.It’s set on val only.The val would be created at run-time when it is required

lateinit is a modifier used with var and used to set the value to the var at a later point

Example

val x:Int by lazy {10}

lateinit var y : String

10.How to create Singleton classes?

To use singleton pattern for our classes we must use “object” keyword before the class

object SingletonClass

An object cannot have a constructor set.we can use the init block inside it

11.What is a data class in kotlin ?

Data class holds the basic data types.It does not contain functionality.

Example

data class User(val name:String,val age:Int)

12.Does kotlin support static keywords ? How to create static methods in kotlin ?

No,Kotlin does not contain any static keyword

To create static method in kotlin ,we have to use “companion object”

Example

class Test

{

companion object

{
fun a( ) : Int=5

}

}

To invoke simple use ,Do simply Test.a( )

13.What is init block in kotlin ?

Init is initializer block in kotlin.It is executed once the primary constructor is instantiated.If you invoke a secondary constructor ,then it works after the primary one as it is composed in the chain.

14. What is the Target Platform of kotlin ? How is kotlin-java interoperability possible ?

Java virtual machine(JVM ) is the target platform of kotlin.Kotlin is 100% interoperable with java because it produces bytecode after compilation.

15.How is a function declared ? Why are kotlin functions known as top-level functions ?

fun add(a:I nt , b: Int) : Int

{

return a+b
}

function retired typed is defined after the :

16.What is the entry point of every kotlin program ?

The “main” function is the entry point  of every kotlin program.In kotlin we can choose not to write the main function inside the class.On compiling the JVM implicitly encapsulates it in a class.

The strings passed in the form of Array<String>  are used to  the command line arguments.

17. Does kotlin allow us to use primitive data types such as int , float & double ?

No,Kotlin does not support primitive data types like java.At the language level,we can not use the above mentioned types,But the JVM bytecode that is compiled does certainly have them.

18.What is the difference between val and var variables ?

val variables are similar like final variables in java.It’s value can not change once assigned.

var variables are similar like normal variables in java.It’s value can be changed multiple times once assigned

Example:

val s : String=”suman”

var x=10

19. What operator is used to handle null  exceptions in kotlin ?

Elvis operator is used to handle null pointer exceptions in kotlin

20.What are High-Order functions in kotlin ?

Higher-Order function is a function that takes functions as parameters or returns a function

Best of Luck !!!!!

sumankumar80

Hello Friends,I have written and developed this website because you can learn technology easily ,prepare for the placement and also for the any type of examination . By :Suman Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *