-
Book Overview & Buying
-
Table Of Contents
Android Programming for Beginners - Fourth Edition
By :
Up to now, our classes like Car, Elephant, and Track have been empty shells. They represent something, but they don't contain any data. Most useful classes will store information about the thing they represent, and that's where properties come in.
We already know that a variable is simply a piece of data; in this context, it is a piece of data that belongs to an instance of the class. Therefore, we give variables in classes another name. They are properties. Properties also have features that differ from variables, but we will get to that. Note that if you have more than one instance of a class, each instance has its own set of data.
There are exceptions where instances can share data, but that is the exception, not the rule, and we will cover that later.
At this stage, it is worth discussing properties and variables further, as I have been using the terms interchangeably. A variable is any named type. It could be something we declare with val...