kotlin interview questions

kotlin important topics  And Kotlin Code :


What is lambda in Kotlin?
Lambda is a function which has no name. Lambda is defined with a curly braces {} which takes variable as a parameter (if any) and body of function. The body of function is written after variable (if any) followed by -> operator.
What is private Lateinit VAR in Kotlin?
The lateinit var lookupKey in Kotlin defined a property without a value set directly. The value is set to the property later. The compiler takes care to add assertions to make sure it is not possible to read the value before it is not initialized.
What is SAP data class?
Data class. The data class defines the physical area of the database (for ORACLE the TABLESPACE) in which your table is logically stored. If you choose a data class correctly, your table will automatically be assigned to the correct area when it is created on the database.
What is the use of data class in SAP ABAP?
If you choose the data class correctly, your table is automatically assigned to the correct area (table space or DB space) of the database when it is created. Each data class corresponds to a physical area in which all the tables assigned to this data class are stored.
Does Kotlin support primitive data types?
Kotlin doesn't have primitive type (I mean you cannot declare primitive directly). It uses classes like Int , Float as an object wrapper for primitives. When kotlin code is converted to jvm code, whenever possible, "primitive object" is converted to java primitive.
What is encapsulation in Kotlin?
As far as i know, encapsulation is a mechanism when you create inaccessible properties in your class by setting them with Private modifier and then you create your own Public methods or functions to enable to access to them.
Does Kotlin use static keyword?
Now, in Android development, things are moving from Java to Kotlin and one of the biggest problems that the developers face while migrating from Java to Kotlin is making a static method because in Kotlin there is nothing as such static . Yes, you heard it right, Kotlin doesn't have a static keyword
What is inline fun in Kotlin?
An inline function is declare with a keyword inline. The use of inline function enhances the performance of higher order function. The inline function tells the compiler to copy parameters and functions to the call site. The virtual function or local function cannot be declared as inline
Is val a constant in Kotlin?
Constants in Kotlin
Kotlin constants are used to define a variable that has a constant value. The const keyword is used to define a constant variable. The const keyword can only be used with the val keyword and not with the var keyword.
What is Kotlin final?
The final modifier mark classes and methods as not allowed to be overridden. In Kotlin this is the default. This decision was made to avoid fragile base class problem. It happens when a small change in base classes (super classes) make subclasses to malfunction. 
What is string interpolation in Kotlin?
String interpolation is variable substitution with its value inside a string. In Kotlin, we use the $ character to interpolate a variable and ${} to interpolate an expression. Kotlin string formatting is more powerful than basic interpolation..

What is Inner class :

Inner class is a class which is created inside another class with keyword inner. In other words, we can say that a nested class which is marked as "inner" is called inner class. Inner class cannot be declared inside interfaces or non-inner nested classes. class outerClass{ //outer class code.

What is Lazy in kotlin :

Lazy is mainly used when you want to access some read-only property because the same object is accessed throughout.

About kotlin for loop :

Kotlin for loop is used to iterate a part of program several times. It iterates through arrays, ranges, collections, or anything that provides for iterate. Kotlin for loop is equivalent to the foreach loop in languages like C#.

 About kotlin Lambda Function loop :

Lambda is a function which has no name. Lambda is defined with a curly braces {} which takes variable as a parameter (if any) and body of function. The body of function is written after variable (if any) followed by -> operator.
Syntax of Lambda expression – :
val lambda_name : Data_type = { argument_List -> code_body }:
// with type annotation in lambda expression
val sum1 = { a: Int, b: Int -> a + b }

// without type annotation in lambda expression
val sum2:(Int,Int)-> Int = { a , b -> a + b}

fun main(args: Array<String>) {
	val result1 = sum1(2,3)
	val result2 = sum2(3,4)
	println("The sum of two numbers is: $result1")
	println("The sum of two numbers is: $result2")

	// directly print the return value of lambda
	// without storing in a variable.
	println(sum1(5,7))
}

Inline Function in kotlin :

An inline function is declare with a keyword inline. The use of inline function enhances the performance of higher order function. The inline function tells the compiler to copy parameters and functions to the call site.The virtual function or local function cannot be declared as inline.:
inline fun higherfunc( str : String, mycall :(String)-> Unit){
// inovkes the print() by passing the string str
mycall(str)
}
// main function
fun main(args: Array<String>) {
print("GeeskforGeeks: ")
higherfunc("A Computer Science portal for Geeks",::print)
}

Kotlin Array :

Syntax:
val num = arrayOf(1, 2, 3, 4)   //implicit type declaration
val num = arrayOf<Int>(1, 2, 3) //explicit type declaration
Kotlin program of creating array using arrayOf() and arrayOf<Int> functions-
fun main()
{
	// declaring an array using arrayOf()
	val arrayname = arrayOf(1, 2, 3, 4, 5)
	for (i in 0..arrayname.size-1)
	{
		print(" "+arrayname[i])
	}
	println()
	// declaring an array using arrayOf<Int>
	val arrayname2 = arrayOf<Int>(10, 20, 30, 40, 50)
	for (i in 0..arrayname2.size-1)
	{
		print(" "+arrayname2[i])
	}
}

Rajeshbhatt12

My name is Rajesh Bhatt. I am working as a senior android developer . I have created this blog for kotlin ,java and Android Development interview questions etc..

Previous Post Next Post