Properties

Classes can have properties. Similarly to regular variables, properties declared using the var keyword are mutable, i.e. they can be reassigned.


Syntax of a property

To declare a read-only property, we should use the val keyword.


AndroidManifest.xml

Each object has it’s own unique values for it’s clas properties. In order to use properties, simply refer to it by name on the object using a dot.


Usage of properties

One more example


Example

We have here a User class, what has a Primary Constructor whit 3 arguments. In this case we can assign value to the unmutable (var) variable.

We can get or set the properties of an object using the dot (user.age) notation.

Questions

I hope the description was understandable and clear. But if you have still questions, then leave me comments below! 😉

Have a nice a day! 🙂  

 


 

Follow and like us:

2 thoughts on “Properties”

Leave a Reply

Your email address will not be published. Required fields are marked *