The full score of this test is 160 points. Take a test to see how many points you can get <<<
1) Does the Kotlin language have basic data types? (5 points)
2) What are the access control characters in Kotlin and what do they mean? What is the default access controller? (5 points)
3) Does a Kotlin interface allow methods to be implemented? Is it allowed to declare member variables? (5 points)
4) What does the Sealed class do? (5 points)
5) How to create an anonymous inner class object similar to Java in Kotlin language? (10 points)
6) What are the advantages of Kotlin's extension over inheritance? Does the execution of extension methods also follow polymorphism? (10 points)
7) If a class implements multiple interfaces at the same time, and there is a method with the same name in the interface, how to resolve the conflict? (5 points)
8) Does the static keyword exist in the Kotlin language? If not, how to declare static variables and implement interoperability with Java (5 points)
9) Is it necessary to avoid null pointer exceptions when using Kotlin language? Why? (10 points)
10) What is the recommended way to judge whether two objects are equal in Kotlin language? How to tell if two objects are the same object? (5 points)
11) If using Foo\
12) How to customize setter/getter methods? (5 points)
13) var x = null
Is it legal to declare variable x using a statement? If legal, what is the concrete type of x? (5 points)
14) What is the output of the following code? (10 points)
val list = listOf(1, 2, 3)
list.add(4)
println(list)
15) What is the result of the execution of the following code? (5 points)
// Kotlin端
object A {
fun init() {
println("A init")
}
}
// Java端
A.init()
16) What is the result of the execution of the following code? (5 points)
fun sum(a: Int, b: Int) = { a + b }
println(sum(1, 3))
17) What is the result of the execution of the following code? (5 points)
println(null is Any)
println(null!! is Nothing)
18) What is the result of the execution of the following code? (10 points)
class A {
init() {
f()
}
val a = "a"
fun f() {
println(a)
}
}
fun main(args: Array<String>) {
A()
}
19) What is the result of the execution of the following code? (10 points)
println(127 as Int? === 127 as Int?)
println(128 as Int? === 128 as Int?)
20) What is the result of the execution of the following code? If the operation is abnormal, how should I modify it to achieve the expected effect? (10 points)
(1..5).forEach {
if (it == 3) break
println(it)
}
21) What is the result of the execution of the following code? If the operation is abnormal, what should be modified, and why should it be modified? (10 points)
val A.x: Int = 3
println(A().x)
22) What is the result of the execution of the following code? (10 points)
fun isOdd(x: Int) = x % 2 != 0
fun length(s: String) = s.length
fun <A, B, C> compose(f: (B) -> C, g: (A) -> B): (A) -> C {
return { x -> f(g(x)) }
}
fun main(args: Array<String>) {
val oddLength = compose(::isOdd, ::length)
val strings = listOf("a", "ab", "abc")
println(strings.filter(oddLength))
}
Note: The version of Kotlin in this example is 1.2.31, and there may be some differences in the updated version
Here is your base level:
Score | evaluate |
---|---|
0 ~ 80 | poor foundation |
80 ~ 108 | good foundation |
108 ~ 160 | The base is great |
View answer method
Scan the QR code below on WeChat to follow Ouyang Feng's studio , and reply to "Kotlin Test Answers" to get the answers to the current test questions
Welcome to the Kotlin Exchange Group
If you also like Kotlin language, welcome to join my Kotlin communication group: 329673958, and join us in the promotion of Kotlin language.