您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)


Content Index

Content Page # 40

Constants

The keyword final is used to indicate that something is a constant. For example:

final double pi = 3.1415926;

final int numberOfSidesInATriangle = 3;

The use of constants can make a program much easier to understand, and prevent the programmer making errors which, although trivial, are rather difficult to trace.

We have seen examples of constants used in the BallWorld application from the previous unit. Constants were introduced to define the width and height of the window the balls bounced within:

final int frameWidth = 600;

final int frameHeight = 400;

In fact, as they appeared in the application, these constants were declared with two more keywords:

public static final int frameWidth = 600;

public static final int frameHeight = 400;

however, we shall leave investigation of the keywords public and static until later units.

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg