Android interview Kotlin questions collation

Kotlin interview questions finishing

1. What is kotlin

Kotlin is a statically typed programming language developed by JetBrains and runs on the JVM .

 

2. Why use Kotlin language

Kotlin language is concise and efficient, there is not so much redundant code, and it is empty safe.

 

3. Explain the extension function

The extension function is used to extend the class without deriving from the class

 

4. What does null safety in Kotlin mean?

The feature of null safety is to avoid the problem of null pointer exceptions, and can also be used to distinguish between null references and non-null references.

 

5. Why is Kotlin and Java interoperable?

Because they are the same after compilation for jvm, byte code runs on jvm after compilation

 

6. Is there a ternary operator in kotlin

does not exist

 

7. How to declare a variable in Kotlin

var name: String

 

8. How many constructors are there in Kotlin

Two, one is the primary constructor, the other is the secondary constructor

 

9. Talk about the extension method of Java.io.file in Kotlin

bufferedReader,readBytes,readText,forEachLine,readLines

 

10. How does kotlin handle empty exceptions

Use elvis operator to handle null exceptions? :,?

 

11. What are the characteristics? Kotlin has but java does not

null safety,operator overloading,coroutines, range expressions, smart cast, compaion object

 

12. The role of data classes in kotlin

The data class contains basic data types, but it does not contain any functional functions

 

13. Can java code be converted into kotlin code?

Can be converted in AndroidStudio or JetBrains

 

14. Does Kotlin allow macros?

Kotlin does not support macros

 

15. The default behavior of the Kotlin class

Kotlin is final by default. Because kotlin supports multiple class inheritance, the cost of open classes is much higher than final classes

 

16. Does kotlin support primitive data types?

Kotlin does not support primitive data types

 

17. What is the range operator

The range operator is used to traverse a range, represented by two dots

for(i in 1..5)

    print(i)

 

18. Does Kotlin provide additional functions for standard Java libraries and classes?

The kotlin program runs on a standard java virtual machine, so there is no difference between kotlin and java at this level, and java can also be run directly in the kotlin program

 

19. Define a volatile variable in Kotlin

volatile var x: Long? = null

 

20.What is the role of abstraction in kotlin

Abstraction is the most important concept of object-oriented programming. The characteristics of abstract classes: You know what functions this class has, but you don't know how to implement these functions and which functions are implemented in detail.

 

21. How to compare two strings in Kotlin

(1)==

(2).equals(Any?)

 

22. What is the use of the following code?

bar {

System.out.println("1111")

}

As a function, bar is receiving an expression as a parameter. This expression prints a line of string

 

23, Kotlin higher-order functions

 

Guess you like

Origin blog.csdn.net/nsacer/article/details/108523414