Created
June 9, 2023 05:34
-
-
Save kalaiselvan369/f75b54708c9b7c4daa18a34f2e15e144 to your computer and use it in GitHub Desktop.
Class definition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun main() { | |
| val dog = Dog() | |
| dog.bark() | |
| } | |
| // class is a user defined data type | |
| class Dog { | |
| // characteristics/properties of a class | |
| val legs: Int = 4 | |
| val color: String = "Black" | |
| // member functions | |
| // behavior of a class | |
| fun run() { | |
| // this keyword is a reference to the class or object that this function belongs | |
| this.bark() // bark while running | |
| } | |
| fun bark() { | |
| } | |
| fun sleep() { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment