Next: Example of a class
Up: Unit 03
Previous: Classes seen as modules
Definition of a class
Syntax:
public class Name {
field-1
...
field-n
}
- Name is the name of the class
- field-1 ...field-n are the
fields of the class, which represent its properties. Each
field-i can be either a data field or an
operation field:
- a data field (or instance variable) is a variable
declaration (see later)
- an operation field (or method) is a method definition
(see later)
Each field is qualified with an access modifier, which determines its
visibility outside the class (see later).
Semantics:
Defines a class.
- The data fields (or instance variables) are used to represent the
internal structure of the objects of the class.
- The operation fields (or methods) are used to realize the
functionalities of the class.
The details will be shown later.
Next: Example of a class
Up: Unit 03
Previous: Classes seen as modules