Browsing category:

Programming

Kotlin Data Classes

In this tutorial we are going to discuss kotlin data classes, and show some examples on how you can use them in your app. We frequently create classes whose main purpose is to hold data. In such a case some standard functionality and utility functions are often mechanically derivable from the data.

Kotlin Function Overriding Rules

Overridden functions of an open class is open by default and we can stop that by using the final Keyword Meaning we can override and inherit overridden method by default. Let’s say we built a learning app. Course is our abstract class, KotlinCourse inherits or extends Course, SpecialKotlinCourse also inherits or extend KotlinCourse. As you can see from the code […]

Kotlin Interface Examples

Interface define contract for classes. An interface is similar to a class just that, it’s a collection of abstract methods and variables. Essentially Interfaces are one level more abstract than abstract classes. Let’s say we have an interface called Driveable. interface Driveable { fun drive() // declaring ‘abstract’ is implicit and unnecessary } we can then have […]

Kotlin: Open & Abstract Classes and Inheritance

In object-oriented programming, inheritance enables new objects to take on the properties of existing objects. We can have class that can inherit properties and methods from the parent class, when we inherit classes, we do not need to specify the method and properties again, in the new class (child class or sub class). In essence it allow us to […]

Kotlin: Class Examples

Class without a Constructor but with default variable (or properties or data) [box type=”info” align=”” class=”” width=””]In class-based object-oriented programming, a constructor is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.[/box] class Person { […]

Kotlin: Function or Methods Example

Simple Function. neither accepts nor return any variable or value fun helloWorld(){ println(“Hello World”) }  Function that takes a parameter but returns no value fun stringFunction (text : String){ for (c in text){ println(“$c “) //KOTLIN -> K O T L I N } } fun intFunction(int : Integer){ println(int) } Functions that returns a […]

Kotlin: Break and Continue Statements

Break and Continue Statements allow us to define jumps in our code and they are used inside Loops breakstatement allow us to jump to the end of the loop and halt any further iterations. This is useful whenever we  are interested in the first occurrence of something. val string = “Kotlin” for (char in string){ […]