Class definition

Class definition is a set of member definitions which are described between the "class" and the "endclass". It decides statuses and behaviours of the class.


Table of contents:


Format

class

Class name

Member definition

endclass

Example

Format

The format of the class definition is:


"class" Class name

Member definitions

"endclass"


It is definition that start with the class keyword and end with the endclass keyword.

The class definition will generate a scope.

class

The class keyword is the start symbol for the class definition. Since it is a keyword, it cannot be used as an identifier.

Class name

It specifies the class name after "class". The naming rules for class name is the same as for identifiers.

Rice does not have a mechanism for avoiding class name collisions like namespaces in other languages.

For the class name, specify a unique name that does not conflict with other classes.

Member definition

Member definitions are:


Field declaration

Fitter definition

Setter definition

Getter definition

Method definition


The field declaration determines the state of the class and the other member definitions determine the behavior.

There is no limit to the order and number of member definitions.

endclass

The endclass keyword is the end symbol for the class definition. Since it is a keyword, it cannot be used as an identifier.

You can use the abbreviation "ec" instead of "endclass". Note that "ec" is also a keyword.

Example

As an example, we reprint the definition of main class. We've already mentioned that the main class is a special class, but it's definition is the same as other user-defined classes.

1:

class main

2:

open method void start()

3:

endmethod

4:

open method void end()

5:

endmethod

6:

ec // Abbreviation

It has defined the class name "main", the start() method, and the end() method.

Copyright © Rice All rights reserved.