From the course: Build Spring Boot Apps with the Kotlin Programming Language
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Functions within a class
From the course: Build Spring Boot Apps with the Kotlin Programming Language
Functions within a class
- [Narrator] So, so far we've created classes, we've created parameters, we've over-ridden the gets and sets, we've looked at constructors. Now let's look at methods within a class. Or to use the correct Kotlin terminology, functions. Well, you can probably guess that you would create a function in a class just like a function that lives outside of a class. So, for example, if we wanted to create a function that gives us the name in upper case, we could write something like, fun, let's say upper case, name. It's not going to to take any parameters. It is going to return a string. And the implementation would be to return the name dot to upper case. (typing) That will work absolutely fine we can call it-- I don't think I'm going to even bother writing the code that we'll call it. And actually just to tidy this up of course we could write this as a single line expression. We don't need the return type, we can just put an equal sign in and we don't need curly brackets and we don't need…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Project structure and packages2m 5s
-
(Locked)
The class declaration and class-level attributes3m 31s
-
Instantiating a class and accessing class-level attributes2m 14s
-
(Locked)
Creating a simple constructor5m 7s
-
(Locked)
Secondary constructors5m 20s
-
(Locked)
Alternative class design5m 3s
-
(Locked)
Overriding getters and setters7m 21s
-
(Locked)
Functions within a class2m 57s
-
(Locked)
Static functions3m 28s
-
(Locked)
Data classes7m 32s
-
(Locked)
-
-
-
-
-
-
-
-
-
-
-
-
-
-