Vidyalelo
Computer Science · all questions

Kotlin Programming MCQ for Competitive Exams, Interviews, and Certifications
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

292

Questions

8/15

Page

Pick an option on a question to see the right answer and solution.

val short for Value, a constant which cannot be changed once assigned?

Select an option to see the answer and solution.

The function typeChecker receiver a parameter obj of type Any. Based upon the type of obj, it prints different messages for Int, String, Double, and Float types; if not any of the mentioned types, it prints "unknown type". What operator allows you to determine the type of an object?

Select an option to see the answer and solution.

You have created a class that should be visible only to the other code in its module. Which modifier do you use?

Select an option to see the answer and solution.

You are upgrading a Java class to Kotlin. What should you use to replace the Java class's static fields?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

You are attempting to assign an integer variable to a long variable, but Kotlin compiler flags it as an error. Why?

Select an option to see the answer and solution.

Which line of code shows how to display a nullable string's length and shows 0 instead of null?

Select an option to see the answer and solution.

Kotlin interfaces and abstract classes are very similar. What is one thing abstract class can do that interfaces cannot?

Select an option to see the answer and solution.

Inside an extension function, what is the name of the variable that corresponds to the receiver object

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which of the following targets are currently not supported by Kotlin?

Select an option to see the answer and solution.

Which of the following constructors are available in Kotlin?

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Which keyword is used to define an immutable variable?

Select an option to see the answer and solution.

Is Kotlin interoperable with Java programming language?

Select an option to see the answer and solution.

Which of the following options is used to write null-safe code in Kotlin?

Select an option to see the answer and solution.