Next: Classes seen as modules
Up: Unit 03
Previous: Overloading of methods
Abstraction on objects is realized as follows:
- We group similar objects (i.e., objects with the same properties) into
classes.
- We establish the properties that are relevant for the objects, and in
particular, the operations that they support (note that this requires to
perform an abstraction on operations).
The ability to support in a very advanced way the abstraction on objects is the
fundamental feature of all object-oriented programming languages (such as Java,
C++, C#, etc.). In these languages, such a form of abstraction is supported
by the ability to define classes directly at the programming language
level.
In Java, the definition of a class is characterized by:
- the name of the class, which identifies the class itself, and
hence identifies the type of its instances;
- the instance variables (also called data fields), which
allow us to store data inside the objects;
- the (instance) methods (also called operation fields),
which can be invoked on the objects of the class to perform operations on
them.
Note: The instance variables and the methods represent the properties of
the objects of a Java class.
Moreover, through suitable access modifiers, we can specify:
- which fields should be visible to the outside the class, i.e., to the
clients of the class - such fields are called public;
- which fields should be hidden to the clients since they are not relevant
for them - such fields are called private.
Next: Classes seen as modules
Up: Unit 03
Previous: Overloading of methods