Android Glossary: Object
Android Glossary: Object
ACCESS MODIFIER
A computer is a machine that follows a list of instructions called a program. An Android device is a computer, and
an app is a program. Inside the device are containers called variables that hold values such as numbers or pieces of
text.
An object is a variable that is special in two ways. First, it can contain smaller variables inside it, called the fields of the
object. Second, attached to an object we can have lists of instructions—in effect, little programs—called methods.
Big variables that contains small variables called objects. Now objects can have
further variables (fields) or methods (Instructions).
OBJECT
METHOD
FIELD [Small
Variables] [List of
Instructions]
There are many classes (types) of objects. Each object of a given class has the same set of fields and methods. For
each class, we have to write a definition: a listing of the fields and methods that belong to each object of that class.
Class 1 Class 2
ME ME
FIE FIE
OBJECT
LD
TH OBJECT
LD
TH
OBJECT OBJECT
MET
[S
mal
OD
[Lis
[S
mal
OD
[Lis
MET FIEL t of t of
FIEL HOD HOD l l
D D Var Inst Var Inst
[List [Smal [List ruct ruct
[Smal of iabl iabl
l of l es] ion es] ion
Instru Varia Instru s] s]
Varia ctions
bles] ction bles]
s] ]
The code sample is a definition for a class named Car. Each Car object contains a field named mModel, holding the
model number of that particular Car object. Each Car object also has two constructor methods, exactly one of which
must be called (executed) when the Car is created. Each constructor puts a value into the mModel field of its newborn
Car object, and also calls a method named setup to finish setting up the object.
The class definition specifies an access modifier for each field and method of its class. For example, the constructors
of class Car are public: they can be called in the methods of another class of objects in the app. This makes it possible
for objects of other classes to create objects of class Car. On the other hand, the mModel field is private: it can be
mentioned only within the methods of the class to which it belongs. We say that a field has been encapsulated when
its access modifier is private. The setup method is private too, because it is intended for use only by the other
methods of this class.
In short, Access modifier depends on the definition of a Class. If one Class is Public
then methods of this class can be called by objects of another Class to create objects in
another Class. On the other hand, if any field Access modifier is private then it is
encapsulated and it can be called/mentioned with in methods of that class only.
Want to insert a picture from your files or add a shape or text box? No problem! In the Insert tab
of the ribbon, simply tap the option you need.