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
From the course: Programming for Non-Programmers: Android & Kotlin
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…
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
-
-
-
-
How programming works3m 58s
-
(Locked)
Variables3m 33s
-
(Locked)
Working with variables5m
-
(Locked)
Using properties2m 53s
-
(Locked)
Connect visual objects to variables6m 39s
-
(Locked)
Enum values5m 30s
-
(Locked)
Private properties and constants4m 53s
-
(Locked)
Practical applications of variables2m 22s
-
(Locked)
Challenge: Create two variables1m 9s
-
(Locked)
Solution: Create two variables2m 41s
-
-
-
-
-
-