Login
Sign up
Categories
IT & Programming
Design & Multimedia
Writing & Translation
Sales & Marketing
Admin Support
Engineering & Manufacturing
Finance & Management
Website Designing & Development
Database Management
Networking & Troubleshooting
Aviation & Aerospace
Softwares & Applications
Stocks & Investments
Electronics & Appliances
Online Tools
General Knowledge & Aptitude
Mathematics
Educational Subjects & Courses
Business & Organization
Health & Wellbeing
Culture & Ethics
IT Field Knowledge & Experience
Languages & Communication
Entrepreneurship & Leadership
Economics & Development
Mass Communication & Media
Research Methods & Evaluation
Public Relations & Dealings
Educational Methods and Research
Educational Subjects & Techniques
Crime & Justice
Governments & Policies
Cyber Security & Ethical Hacking
Hospitality & Tourism
Soft Skills & Personal Management
Transportation & Driving Rules
Forest and Nature
Religion
Skill Assessment
MCQs
Login
Sign up
Categories
IT & Programming
Design & Multimedia
Writing & Translation
Sales & Marketing
Admin Support
Engineering & Manufacturing
Finance & Management
Website Designing & Development
Database Management
Networking & Troubleshooting
Aviation & Aerospace
Softwares & Applications
Stocks & Investments
Electronics & Appliances
Online Tools
General Knowledge & Aptitude
Mathematics
Educational Subjects & Courses
Business & Organization
Health & Wellbeing
Culture & Ethics
IT Field Knowledge & Experience
Languages & Communication
Entrepreneurship & Leadership
Economics & Development
Mass Communication & Media
Research Methods & Evaluation
Public Relations & Dealings
Educational Methods and Research
Educational Subjects & Techniques
Crime & Justice
Governments & Policies
Cyber Security & Ethical Hacking
Hospitality & Tourism
Soft Skills & Personal Management
Transportation & Driving Rules
Forest and Nature
Religion
Skill Assessment
MCQs
Login
Sign up
Skill Assessments
>
IT & Programming
>
Kotlin Skill Assessment
>
Quiz # 2
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.
Start Quiz
Kotlin Quiz # 2
End Quiz
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)
Println(students.groupBy{ it.lastName }.count())
Println(students.groupBy{ it.lastName.first() }.fold().count())
Println(students.groupingBy{ it.lastName.first() }.count())
Println(students.groupingBy{ it.lastName.first() }.size())
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)}
.sortedByDescending()
.descending()
.sortedDescending()
.sort(
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?
Lateinit var name: String // lateinit is modifier not delegate
Var name: String by lazy
Var name: String by Delegates.notNull()
Var name: String? = null
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?
Delegates.vetoable()
Delegates.cancellable()
Delegates.observer()
Delegates.watcher()
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?
Val sorted = fibonacci().skip(3).take(6).sortedDescending().toList()
Val sorted = fibonacci().skip(3).take(6).sortedByDescending().toList()
Val sorted = fibonacci().skip(3).limit(6).sortedByDescending().toList()
Val sorted = fibonacci().drop(3).take(6).sortedDescending().toList()
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)
Val c = list of (a, b)
Val c = a + b
Val c = listOf(a+b)
Val c = listOf(*a, *b)
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}")
Replace !!. with ?.
Replace !!. with ?:.
Surround the line with a try/catch block.
Replace !!. with ?.let.
What is the execution order of init blocks and properties during initialization?
All of the properties are executed in order of appearance, and then the init blocks are executed.
The init blocks and properties are executed in the same order they appear in the code.
All of the init blocks are executed in order of appearance, and then the properties are executed.
The order of execution is not guaranteed, so code should be written accordingly.
What are the two ways to make a coroutine's computation code cancellable?
Call the yield() function or check the isActive property.
Call the cancelled() function or check the isActive property.
Call the stillActive() function or check the isCancelled property.
Call the checkCancelled() function or check the isCancelled property.
Which statement declares a variable mileage whose value never changes and is inferred to be an integer?
Val mileage:Int = 566
Var mileage:Int = 566
Val mileage = 566 (Note: inferred)
Const int mileage = 566
What is the preferred way to create an immutable variable of type long?
Var longInt = 10L
Const long longInt = 10
Val longInt = 10L
Val longInt:Long = 10
Which line converts the binaryStr, whish contain only 0s and 1s, to an integer representing its decimal value? val binaryStr = "00001111"
Val myInt = toInt(binaryStr)
Val myInt = binaryStr.toInt(
Val myInt = binaryStr.toInt()
Val myInt = binaryStr.toInt(2)
In a Kotlin program, which lines can be marked with a label
Any program line can be marked with a label
Any statement can be marked with a label
Any expression can be marked with a label
Only the beginning of loops can be marked with a label
All classes in Kotlin inherit from which superclass?
Default
Super
Any
Object
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()}
Add
Comparable
> between the fun keyword and the function name
Add Comparable
between the fun keyword and the function name
Add
> between the fun keyword and the function name
Add
> between the fun keyword and the function name
Kotlin classes are final by default. What does final mean?
Final means that you cannot use interfaces with this class.
Final means that this is the only file that can use the class.
Final means that you cannot extend the class.
Final classes cannot be used in the finally section of a try/catch block.
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"
Arrays use zero-based indexes. The value 3 is outside of the array's bounds
You accessed the element with an index but should have used.set().
You declared the array with val but should have used var
You cannot changes the value of an element of an array. You should have used a mutable list.
If a class has one or more secondary constructors, what must each of them do?
Each secondary constructor must call super().
Each secondary constructor must call base().
Each secondary constructor must directly or indirectly delegate to the primary.
Each secondary constructor must have the same name as the class.
When you can omit constructor keyword from the primary constructor?
It can be omitted only if an init block is defined.
It can be omitted anytime; it is not mandatory.
It can be omitted if secondary constructors are defined.
It can be omitted when the primary constructor does not have any modifiers or annotations.
How many different kinds of constructors are available for kotlin classes?
Two.
None.
Four.
One.
What is the default visibility modifier in Kotlin?
Protected
Private
Internal
Public
Submit Test
Prev Question
ABCd
Next Question
Liked this quiz? Share it with friends:
Share Quiz
Share
WhatsApp
Facebook
Twitter
LinkedIn
Or copy link:
Copy
Link copied to clipboard!
Copy
Kotlin Skill Assessment
Login to see Skill Score (It's Free)
Your Skill Level:
Poor
Retake Quizzes to improve it
Start Assessment
Kotlin Skill Assessment
Login to see Skill Score (It's Free)
Your Skill Level:
Poor
Retake Quizzes to improve it
Start Assessment