Kotlin Quiz # 2

Instructions
Quiz: Kotlin Quiz # 2
Subject: Basic Keynote
Total Questions: 21 MCQs
Time: 21 Minutes

Note

  • Do not refresh the page while taking the test.
  • Results along with correct answers will be shown at the end of the test.
Kotlin Quiz # 2
Question 1 of 21
00:00
  • You would like to group a list of students by last name and get the total number of groups. Which line of code accomplishes this, assuming you have a list of the Student data class? Data class Student(val firstName: String, val lastName: String)

  • You have an unordered list of high scores. Which is the simple method to sort the highScores in descending order? fun main() { val highScores = listOf(4000, 2000, 10200, 12000, 9030)}

  • Your class has a property name that gets assigned later. You do not want it to be a nullable type. Using a delegate, how should you declare it?

  • You want to know each time a class property is updated. If the new value is not within range, you want to stop the update. Which code snippet shows a built-in delegated property that can accomplish this?

  • Which line of code shows how to call a Fibonacci function, bypass the first three elements, grab the next six, and sort the elements in descending order?

  • You have two arrays, a and b. Which line combines a and b as a list containing the contents of both? val a = arrayOf(1, 2, 3) val b = arrayOf(100, 200, 3000)

  • This code is occasionally throwing a null pointer exception (NPE). How can you change the code so it never throws as NPE? println("length of First Name = ${firstName!!.length}")

  • What is the execution order of init blocks and properties during initialization?

  • What are the two ways to make a coroutine's computation code cancellable?

  • Which statement declares a variable mileage whose value never changes and is inferred to be an integer?

  • What is the preferred way to create an immutable variable of type long?

  • Which line converts the binaryStr, whish contain only 0s and 1s, to an integer representing its decimal value? val binaryStr = "00001111"

  • In a Kotlin program, which lines can be marked with a label

  • All classes in Kotlin inherit from which superclass?

  • You have written a function, sort(), that should accept only collections that implement the Comparable interface. How can you restrict the function? fun sort(list: List): List { return list.sorted()}

  • Kotlin classes are final by default. What does final mean?

  • You have created an array to hold three strings. When you run the code bellow, the compiler displays an error. Why does the code fail? val names = arrayOf(3) names[3]= "Delta"

  • If a class has one or more secondary constructors, what must each of them do?

  • When you can omit constructor keyword from the primary constructor?

  • How many different kinds of constructors are available for kotlin classes?

  • What is the default visibility modifier in Kotlin?

Liked this quiz? Share it with friends:

Kotlin Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

Kotlin Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it