Kotlin MCQs with answers Page - 14

Here, you will find a collection of MCQ questions on Kotlin. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 828.03K Points
Coach

Q. Which of the following is the correct way to declare a data class?

  • (A) data class User(val name: String)
  • (B) class User(val name: String) data
  • (C) val User = data class(name: String)
  • (D) data(User: class String)

A

Admin • 828.03K Points
Coach

Q. What is the return type of a lambda in Kotlin by default?

  • (A) Int
  • (B) Unit
  • (C) Any
  • (D) Void

A

Admin • 828.03K Points
Coach

Q. How do you safely access a property that may be null?

  • (A) property?
  • (B) property!!
  • (C) property.?name
  • (D) property?.name

A

Admin • 828.03K Points
Coach

Q. Which method returns the index of the first matching element?

  • (A) indexOf()
  • (B) findIndex()
  • (C) firstIndex()
  • (D) search()

A

Admin • 828.03K Points
Coach

Q. Which scope function is used when you need to work with the object and return the result?

  • (A) apply
  • (B) let
  • (C) also
  • (D) do

A

Admin • 828.03K Points
Coach

Q. Which of these is NOT a valid Kotlin keyword?

  • (A) as
  • (B) typeof
  • (C) break
  • (D) when

A

Admin • 828.03K Points
Coach

Q. How do you define a default parameter in Kotlin?

  • (A) val name = "Guest"
  • (B) name: String = "Guest"
  • (C) name = Guest
  • (D) String name = Guest

A

Admin • 828.03K Points
Coach

Q. What does the 'companion object' in Kotlin do?

  • (A) Creates static methods and properties
  • (B) Initializes variables
  • (C) Declares a singleton
  • (D) Overrides constructors

A

Admin • 828.03K Points
Coach

Q. Which keyword is used to import classes in Kotlin?

  • (A) use
  • (B) import
  • (C) include
  • (D) require

A

Admin • 828.03K Points
Coach

Q. Which function returns the last index of a list?

  • (A) endIndex()
  • (B) lastIndex()
  • (C) tailIndex()
  • (D) finalIndex()