Professional Documents
Culture Documents
9.kclass Obj
9.kclass Obj
Class
Object
Kotlin Nested class and Inner class
Content
2 Class
3 Object
Create an object-
Class and Object Example
Class
Like Java, class is a blue print for the objects having similar properties. We
need to dene a class before creating object and class keyword is used to
dene a class. The class declaration consist of class name, class header and
class body enclosed with curly braces.
Syntax of class declaration:
class className { // class header
// property
// member function
}
Object
Create an object-
Accessing the property of the class- We can access the properties of class using an object. First
create an object using the class reference then access the property.
obj.nameOfProperty
obj.funtionName(parameters)
Nested Class
A class is declared within another class then it is called a nested class. By
default nested class is static so we can access the nested class property or
variables using dot(.) notation without creating an object of the class.
Syntax of declaration:
class outerClass {
............
// outer class properties or member function
class nestedClass {
..........
// inner class properties or member function
}
}
In Kotlin, to access the member function of nested class, we need to create the object for nested
class and call the member function using it.
Ranjit Patnaik Kotlin OOP-Concept 9 / 10
Kotlin Class and Objects
Class
Object
Kotlin Nested class and Inner class