Connect 4 Techs
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact
No Result
View All Result
Connect 4 Techs
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact
No Result
View All Result
Connect 4 Techs
No Result
View All Result
Home Kotlin

Kotlin Functions & Classes (Lesson 11 PDF)

Ahmed Elhozayen by Ahmed Elhozayen
October 11, 2026
in Kotlin
0
Kotlin Functions & Classes (Lesson 11 PDF)

Kotlin is a statically typed programming language that runs on the Java Virtual Machine (JVM). It was developed by JetBrains and is now an official language for Android development. Kotlin is designed to be concise, expressive, and safe.

It is also interoperable with Java, which means that you can use Kotlin and Java code together in the same project.

You might also like

Kotlin Class Functions & Inheritance (Lesson 13 PDF)

Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)

Kotlin

Kotlin Functions & Classes (Lesson 11 PDF)

Overview about the Lesson

In this lesson, we’ll cover the basics of Kotlin Functions & Classes, including how to create and use functions, how to create classes and objects, and how to work with inheritance and polymorphism.

The Content Of The Lesson

The lesson is divided into the following sections:

  • Creating and using functions
  • Creating classes and objects
  • Working with inheritance
  • Working with polymorphism
  • Using interfaces
  • Using abstract classes

Why This Lesson

Functions & Classes are fundamental concepts in programming, and Kotlin provides excellent support for working with them. By the end of this lesson, you’ll have a solid understanding of Kotlin Functions & Classes and how to use them in your programs.

Kotlin Functions: Syntax and Examples

The PDF covers functions and an introduction to classes. This section concentrates on functions, which you will write in every Kotlin program. Classes are covered in depth in Lessons 12 and 13.

Declaring and calling a function

fun greet(name: String): String {
    return "Hello, $name!"
}

fun main() {
    println(greet("Laila"))   // Hello, Laila!
}
  • fun starts the declaration, followed by the name and parameters with their types.
  • The return type comes after the parentheses (: String).
  • A function that returns nothing has the type Unit, which you can omit.

Single-expression functions

fun square(x: Int) = x * x
fun isEven(n: Int) = n % 2 == 0

fun main() {
    println(square(6))    // 36
    println(isEven(7))    // false
}

When the body is one expression, replace the braces and return with =. The return type is inferred.

Default and named arguments

fun price(amount: Double, taxRate: Double = 0.14, discount: Double = 0.0) =
    amount * (1 + taxRate) - discount

fun main() {
    println(price(100.0, 0.10))             // 110.00000000000001 (see note below)
    println(price(100.0, discount = 5.0))   // uses default tax
}

Default values mean you rarely need several overloaded versions of a function. Named arguments (discount = 5.0) make calls self-explanatory and let you skip parameters. (Floating-point results such as 110.00000000000001 are normal for Double; round for display.)

vararg: any number of arguments

fun total(vararg values: Int) = values.sum()

fun main() {
    println(total(1, 2, 3, 4))   // 10
}

Lambdas and higher-order functions

fun main() {
    val double = { x: Int -> x * 2 }
    println(double(21))                          // 42

    val nums = listOf(1, 2, 3, 4, 5)
    println(nums.filter { it > 2 }.map { it * 10 })   // [30, 40, 50]
}

A lambda is a function without a name. Functions such as filter and map take lambdas as arguments, and it is the implicit name of a single parameter.

Extension functions

fun String.shout() = uppercase() + "!"

fun main() {
    println("kotlin".shout())   // KOTLIN!
}

Extensions add functions to existing types without changing their source code.

Practice exercise

Write a function that returns the larger of two numbers, using a single-expression body.

fun maxOf2(a: Int, b: Int) = if (a > b) a else b

fun main() {
    println(maxOf2(8, 13))   // 13
}

Frequently Asked Questions

What is Unit in Kotlin?

Unit is the return type of functions that don’t return a meaningful value, similar to void in Java. You don’t need to write it.

Should parameters be val or var?

Function parameters are always read-only (like val). Copy a parameter into a local var if you need to change it.

Continue the course

← Previous: Lesson 10: For Loops & Ranges  |  Next: Lesson 12: Classes, Objects & Constructors →

  1. Lesson 1: Getting Started
  2. Lesson 2: Syntax & Output
  3. Lesson 3: Comments & Variables
  4. Lesson 4: Data Types
  5. Lesson 5: Operators
  6. Lesson 6: Set Operations & Grouping
  7. Lesson 7: Booleans & If…Else
  8. Lesson 8: When, While, Break & Continue
  9. Lesson 9: Arrays
  10. Lesson 10: For Loops & Ranges
  11. Lesson 11: Functions & Classes (you are here)
  12. Lesson 12: Classes, Objects & Constructors
  13. Lesson 13: Class Functions & Inheritance

Conclusion

In this blog post, we’ve covered the basics of Kotlin Functions & Classes, including how to create and use functions, how to create classes and objects, and how to work with inheritance and polymorphism.

We’ve also explored some advanced topics, such as using interfaces and abstract classes. With this knowledge, you’ll be well-equipped to work with Functions & Classes in your Kotlin programs.

Download From Link

You can download the lesson from the following link:

From Here

Tags: AndroidJavaJVMKotlinProgrammingtechnology
Previous Post

Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)

Next Post

Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

Ahmed Elhozayen

Ahmed Elhozayen

Related Posts

Kotlin Class Functions & Inheritance (Lesson 13 PDF)
Kotlin

Kotlin Class Functions & Inheritance (Lesson 13 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin Classes and Objects & Constructors (Lesson 12 PDF)
Kotlin

Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)
Kotlin

Kotlin For Loop & Kotlin Ranges (Lesson 10 PDF)

by Ahmed Elhozayen
October 11, 2026
 Kotlin Arrays (Lesson 9 PDF)
Kotlin

 Kotlin Arrays (Lesson 9 PDF)

by Ahmed Elhozayen
October 11, 2026
Kotlin When & While Loop, Break & Continue (Lesson 8 PDF)
Kotlin

Kotlin When & While Loop, Break & Continue (Lesson 8 PDF)

by Ahmed Elhozayen
October 11, 2026
Next Post
Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

Kotlin Classes and Objects & Constructors (Lesson 12 PDF)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended

Kotlin When & While Loop, Break & Continue (Lesson 8 PDF)

Kotlin When & While Loop, Break & Continue (Lesson 8 PDF)

October 11, 2026
Three Cs Positioning Framework PDF

Three Cs Positioning Framework PDF

June 25, 2024

Categories

  • apple
  • Canon
  • Data Analysis
  • Excel
  • Finance
  • ios
  • Kotlin
  • Marketing
  • MBA
  • Samsung
  • Software Tutorials
  • Technology

Don't miss it

20 Essential Excel Formulas Every Data Analyst Must Know in 2026
Data Analysis

20 Essential Excel Formulas Every Data Analyst Must Know in 2026

May 18, 2026
Excel guide for data analytics learners
Excel

Excel for Data Analysis PDF

October 11, 2026
The Ultimate Guide to Financial Modeling PDF
Excel

The Ultimate Guide to Financial Modeling PDF

October 11, 2026
The Ultimate Excel Handbook PDF
Excel

The Ultimate Excel Handbook PDF

October 11, 2026
𝟓𝟎 𝐄𝐱𝐜𝐞𝐥 𝐒𝐡𝐨𝐫𝐭𝐜𝐮𝐭 𝐊𝐞𝐲
Excel

50 Excel Shortcut Key PDF: Streamline Your Workflow

March 21, 2025
Most Useful Excel Keyboard Shortcuts For Windows and Mac OS
Excel

Most Useful Excel Keyboard Shortcuts for Windows and Mac OS PDF

March 21, 2025
Connect4Techs Tech

Practical, free guides on Excel, data analysis, finance, business and programming — written to help you learn faster and work smarter.

Follow on Facebook

Topics

  • Excel
  • Kotlin
  • MBA
  • Finance
  • Data Analysis
  • Apple
  • Technology
  • Software Tutorials

Latest articles

  • 20 Essential Excel Formulas Every Data Analyst Must Know in 2026May 18, 2026
  • Excel for Data Analysis PDFAug 31, 2025
  • The Ultimate Guide to Financial Modeling PDFApr 19, 2025

Company

  • About us
  • Contact
  • Privacy Policy
  • Terms of Use
  • IT Certification PDFs
© 2026 Connect4Techs. All rights reserved. Privacy · Terms · Contact
No Result
View All Result
  • Home
  • Excel
  • Data Analysis
  • Finance
  • MBA
    • Marketing
  • Kotlin
  • Gadgets
    • Apple
    • Samsung
    • Canon
    • Tech News
  • About
  • Contact