0% found this document useful (0 votes)
2 views

Advance Kotlin Assignment (1)

The document outlines advanced Kotlin concepts including higher-order functions, lambda expressions, and scoped functions, along with various topics such as data classes, null safety, and exception handling. It features multiple-choice questions and interview questions to assess understanding of these concepts. Additionally, it provides resources for further learning in both Hindi and English.

Uploaded by

adityat9179
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Advance Kotlin Assignment (1)

The document outlines advanced Kotlin concepts including higher-order functions, lambda expressions, and scoped functions, along with various topics such as data classes, null safety, and exception handling. It features multiple-choice questions and interview questions to assess understanding of these concepts. Additionally, it provides resources for further learning in both Hindi and English.

Uploaded by

adityat9179
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Assignment

ADVANCED KOTLIN
CONCEPTS
Deep Dive into
Higher order function,
Lambdas, Scope function and
more
TOPICS TO LEARN

Advanced Kotlin Concepts


Data Classes
Enum & Sealed Classes
Null Safety
Exception Handling
Collections
Higher-Order Functions &
Function Types
Lambda Expressions
Map, Filter, ForEach
Extension Functions & Inline
Functions
Scoped Functions (apply, let,
with, run)
Generics & vararg
Nested & Inner Classes

01 NATIVE KNIGHTS
MULTIPLE CHOICE QUESTION

What is a primary use of data class in Kotlin?


A) To define a custom type for collections
B) To hold immutable data in a structured format
C) To create abstract classes
D) To define inheritance structure

Which function is used to handle nullable types safely?


A) withNull
B) ?.
C) !!
D) as?

In Kotlin, what does let do in the context of scoped


functions?
A) Returns the object it was called on
B) Executes code block and returns a different value
C) Initializes properties with lateinit
D) Acts as a constructor

Which of these keywords in Kotlin allows you to define a


group of possible states for a variable?
A) data
B) enum
C) sealed
D) Both B and C

02 NATIVE KNIGHTS
MULTIPLE CHOICE QUESTION

In Kotlin, the try block can be followed by which of the


following?
A) else
B) finally
C) default
D) do

Which higher-order function in Kotlin can transform each


element in a collection?
A) filter
B) map
C) forEach
D) let

What is the function type syntax in Kotlin?


A) (T) -> R
B) (T) => R
C) (T): R
D) {T -> R}

Which function executes a block of code for each element


in a collection without modifying it?
A) map
B) filter
C) forEach
D) reduce

03 NATIVE KNIGHTS
MULTIPLE CHOICE QUESTION

What does inline mean when used with a Kotlin function?


A) Forces the function to be executed last
B) Makes the function return a default value
C) Inlines the function’s bytecode to improve
performance
D) Allows null values

In Kotlin, vararg is used to:


A) Declare multiple return types
B) Pass a variable number of arguments
C) Override properties
D) Handle exceptions

Which type of function is apply?


A) Scoped function that returns Unit
B) Scoped function that returns the object itself
C) Higher-order function with multiple arguments
D) Default function in Kotlin

What is the purpose of a sealed class in Kotlin?


A) To create classes with mutable properties
B) To restrict the class hierarchy
C) To enforce immutability
D) To create generic classes

04 NATIVE KNIGHTS
GUESS THE OUTPUT

Code Snippet #1

Code Snippet #2

05 NATIVE KNIGHTS
GUESS THE OUTPUT

Code Snippet #3

Code Snippet #4

Code Snippet #5

06 NATIVE KNIGHTS
INTERVIEW QUESTIONS

What are data classes in Kotlin?


Data classes are intended to hold data and automatically
provide useful methods like copy, toString, and equals.

Explain sealed classes and their use cases.


Sealed classes are used to represent restricted class
hierarchies, commonly for modeling states in a finite set.

What is null safety in Kotlin?


Null safety ensures that Kotlin handles nullable types
explicitly, reducing NullPointerException occurrences.

Explain exception handling in Kotlin.


Exception handling uses try, catch, and finally to manage
errors, providing safety and control over unexpected
issues.

What are higher-order functions?


These are functions that take other functions as
parameters or return a function, enhancing flexibility and
reuse.

How do lambda expressions work in Kotlin?


Lambdas are anonymous functions that make code
concise, especially with collections and higher-order
functions.

07 NATIVE KNIGHTS
INTERVIEW QUESTIONS
What is the purpose of extension functions?
Extension functions allow adding functionality to existing
classes without modifying the original code.

Explain the purpose of inline functions.


Inline functions optimize code performance by avoiding
function overhead, especially when lambdas are passed.

What are scoped functions and why are they useful?


Scoped functions like let, apply, run, and with simplify
object modifications and chaining operations.

Explain generics in Kotlin.


Generics enable type-safe and reusable code, allowing
functions and classes to operate on different types.

What is the difference between vararg and Array?


Vararg allows passing a variable number of arguments,
while Array is a collection with fixed or dynamic size.

Describe nested and inner classes in Kotlin.


Nested classes do not hold references to outer classes,
while inner classes do.

How does delegation work in Kotlin?


Kotlin allows class delegation where one class delegates
its behavior to another, reducing code redundancy.
08 NATIVE KNIGHTS
RESOURCES LINK

Hindi Resource -
Kotlin Beginner Tutorials Hindi by Cheey code

English Resource -
Get started with Kotlin | Kotlin Documentation

09 NATIVE KNIGHTS

You might also like