val short for Value, a constant which cannot be changed once assigned?
A. It can be changed but once only
B. It can be changed
C. val cannot be changed after its assigned
D. Both A & B
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?
A. instanceof
B. is
C. typeof
D. assign()
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?
A. internal
B. private
C. public
D. protected
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?
A. an anonymous object
B. a static property
C. a companion object
D. a backing field
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
A. a do..while loop
B. a for loop
C. a while loop
D. a forEach loop
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?
A. You must wrap all implicit conversion in a try/catch block
B. You can only assign Long to an Int, not the other way around
C. There is no implicit conversion from Int to Long
D. All integers in Kotlin are of type Long
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?
A. println(b!!.length ?: 0)
B. println(b?.length ?: 0)
C. println(b?.length ?? 0)
D. println(b == null? 0: b.length)
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?
A. Only abstract classes are inheritable by subclasses
B. Only abstract classes can inherit from multiple superclasses
C. Only abstract classes can have abstract methods
D. Only abstract classes can store state
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
A. The variable is named it
B. The variable is named this
C. The variable is named receiver
D. The variable is named default
Select an option to see the answer and solution.
Which is the proper way to declare a singleton named DatabaseManager?
A. Object DatabaseManager {}
B. Singleton DatabaseManager {}
C. Static class DatabaseManager {}
D. Data class 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?
A. Val sorted = fibonacci().skip(3).take(6).sortedDescending().toList()
B. Val sorted = fibonacci().skip(3).take(6).sortedByDescending().toList()
C. Val sorted = fibonacci().skip(3).limit(6).sortedByDescending().toList()
D. Val sorted = fibonacci().drop(3).take(6).sortedDescending().toList()
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?
A. Each secondary constructor must call super()
B. Each secondary constructor must call base()
C. Each secondary constructor must directly or indirectly delegate to the primary
D. Each secondary constructor must have the same name as the class
Select an option to see the answer and solution.
When can you omit the constructor keyword from the primary constructor?
A. It can be omitted only if an init block is defined
B. It can be omitted anytime; it is not mandatory
C. It can be omitted if secondary constructors are defined
D. It can be omitted when the primary constructor does not have any modifiers or annotations
Select an option to see the answer and solution.
Which of the following targets are currently not supported by Kotlin?
A. LLVM
B. .NET CLR
C. Javascript
D. None of These
Select an option to see the answer and solution.
Which of the following constructors are available in Kotlin?
A. Primary constructor
B. Secondary constructor
C. Both A & B
D. None of These
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"A. Arrays use zero-based indexes. The value 3 is outside of the array's bounds
B. You accessed the element with an index but should have used .set()
C. You declared the array with val but should have used var
D. You cannot change the value of an element of an array. You should have used a mutable list
Select an option to see the answer and solution.
Which keyword is used to define an immutable variable?
A. var
B. val
C. immulvar
D. immutableVar
Select an option to see the answer and solution.
Is Kotlin interoperable with Java programming language?
A. Yes, it is interoperable
B. No, it is not interoperable
Select an option to see the answer and solution.
Which of the following options is used to write null-safe code in Kotlin?
A. Range
B. Sealed Class
C. Elvis Operator
D. Lambda Function
Select an option to see the answer and solution.