Home > MCQs > IT & Programming > Kotlin MCQs

Kotlin MCQ

Kotlin Quick Quiz

Question 1 of 10
  • 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()}

    Answer & Explanation

    Correct Answer: Add > between the fun keyword and the function name

    Note: This Question is unanswered, help us to find answer for this one

  • In this code snippet, why does the compiler not allow the value of y to change? For(y in 1..100) y+=2

    Answer & Explanation

    Correct Answer: Y is an implicitly immutable value

    Note: This Question is unanswered, help us to find answer for this one

  • Which is the proper way to declare a singleton named DatabaseManager?

    Answer & Explanation

    Correct Answer: Object DatabaseManager {}

    Note: This Question is unanswered, help us to find answer for this one

  • Which line of code is a shorter, more idiomatic version of the displayed snippet? val len: Int = if (x != null) x.length else -1

    Answer & Explanation

    Correct Answer: Val len = x?.length ?: -1

    Note: This Question is unanswered, help us to find answer for this one

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

    Answer & Explanation

    Correct Answer: Call the yield() function or check the isActive property.

    Note: This Question is unanswered, help us to find answer for this one

  • All classes in Kotlin inherit from which superclass?

    Answer & Explanation

    Correct Answer: Any

    Note: This Question is unanswered, help us to find answer for this one

  • What three methods does this class have? Class Person

    Answer & Explanation

    Correct Answer: Equals(), hashCode(), and toString()

    Note: This Question is unanswered, help us to find answer for this one

  • Which snippet correctly shows setting the variable max to whichever variable holds the greatest value, a or b, using idiomatic Kotlin?

    Answer & Explanation

    Correct Answer: Val max3 = a.max(b) (Extension Function is One of the idiomatic Solutions in Kotlin)

    Note: This Question is unanswered, help us to find answer for this one

  • What is the default visibility modifier in Kotlin?

    Answer & Explanation

    Correct Answer: Public

    Note: This Question is unanswered, help us to find answer for this one

  • You are writing a console app in Kotlin that processes test entered by the user. If the user enters an empty string, the program exits. Which kind of loop would work best for this app? Keep in mind that the loop is entered at least once

    Answer & Explanation

    Correct Answer: A do..while loop

    Note: This Question is unanswered, help us to find answer for this one

  • Kotlin Quick Quiz

    battery

    Poor Results!

    You need a lot of improvement.

    Just don't give up!

    Correct Answers: 0/10

    Start Practicing with our MCQs given below.