Dear Readers, these Kotlin Interview Questions have been outlined particularly to get you familiar with nature of questions that you may experience during your interview.
If there is any question that has been asked to you during interview kindly post it in the comments section to help future readers.
These Kotlin Interview Questions are also helpful for Android Developers.
I will also keep adding Kotlin Interview Questions on this list.
Answer:-
Because Kotlin has several features which even modern versions of Java lack.
Let’s list down few of them.
Reference:-
Answer:-
Properties which needs to be initialized at compile time and which cannot be assigned during run time are declared using keyword const.
Whereas properties which can be assigned a value at runtime but their value cannot be reassigned are declared using keyword val.
Answer:-
These are two different types of equality in Kotlin.
== represents structural equality in Kotlin.
Whereas === represents referential equality in Kotlin.
Answer:-
Yes, this is a feature of Kotlin / Native which is under development.
It compiles Kotlin code into native code which can be executed without JVM.
Answer:-
Answer:-
String Templates in Kotlin can be evaluated (interpolated).
Reference:-
We can use companion object in Kotlin to declare a class Singleton.
Kotlin companion object also solves the problem of static member and static functions.
Because any property inside companion object can be called without creating an instance of a class.
Example:-
class AppClass : Application() {
companion object {
var instance: AppClass
}
override fun onCreate() {
super.onCreate()
instance = this
}
}
Answer:-
No, Kotlin does not support implicit conversion of smaller types to bigger ones.
We need to explicitly convert Byte to Int before assigning it to an Int variable.
val b: Byte = 1
val i: Int = b.toInt()
Answer:-
Kotlin is null safety language. Means we cannot have a null variable especially in case of primitive data types they can never be null.
But sometimes there are few variables which need to be initialized lately.
So for that Kotlin has a lateinit
keyword which tells the compiler that this particular keyword will be initialized lately.
Consider an example lateinit var myadapter:MyAdapter
, to use it the proper syntax will be myadapter?.let { Do your stuff in body } in a newer version of Kotlin.
We also have a keyword isInitialzed
, other then this we can also use !! to tell the compiler that we are aware of Null Pointer Exception let ignore it.
Reference:-
https://kotlinlang.org/docs/reference/null-safety.html
Answer:-
Answer:-
There are two different types of constructors in Kotlin.
A Primary constructor is part of a class header and is declared after the class name.
A Secondary constructor is declared inside a class body.
A Class can have one or more Secondary constructor.
Answer:-
In Kotlin when
is alternate of Java 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:-
Answer:-
Yes, in that case, each branch of a when statement will work as if else if.
If any branch fulfills its condition its body will be executed.
Answer:-
Answer:-
No, Kotlin does not support Checked Exceptions.
package com.developine.learnkotlin
fun main(args: Array<String>) {
println("hello World")
}
Answer:
Yes, In Kotlin you can declare multiple main functions in different files in same package.
Answer:-
Kotlin does not support implicit conversions.
Answer:-
Answer:-
Kotlin does not support primitive Data Types like in Java.
Answer:-
Answer:-
Yes.
Answer:-
Answer:-
Answer:-
Just like C++ in Koltin we can use functional as well as Object-Oriented Programming approach.
Means We can have functions without class but on compile time Kotlin compiler converts the function, make a static object for it and then call that function by an anonymous class anonymous instance which cause extra memory consumption.
To come over it inline
keyword is used, it copies the code into a class which is calling this method and our method behave as a member of class calling it.
Answer:- Coming Soon…..
Answer:-
We use var
and val
keywords to declare any property mutable or immutable in Kotlin.
Answer:- Coming soon….
Answer:-
A function which can:
Answer:- Coming Soon….
If this article has helped you, please share it 🙂
And if you found any other Kotlin Android Interview questions which can be added in this list, please let me know through comments.