From the course: Programming for Non-Programmers: Android & Kotlin

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using properties

Using properties

From the course: Programming for Non-Programmers: Android & Kotlin

Start my 1-month free trial

Using properties

- [Instructor] In our code, we've created some variables. So I have them inside of this block right here. The onCreate, in what's known in programming as a method. We'll talk more about methods later on. But that's the name of this block of code. So, inside of here we have the variables that we created. Now, if we were to try to access these variables at some other point in our code, we couldn't do it. These variables are only known to this method. So any other method, or any other event that happens in our code, like a button press, cannot access the values of these variables. So keep that in mind when you're creating your variables. Sometimes what you want to do is have variables that can be accessed anywhere in your code. These variables are referred to as properties. Some other languages call these fields or instance variables. Properties can be created by declaring them in a different spot than inside of a method like we've done earlier. To declare a property, write it underneath…

Contents