Home News DOC Class DL Others Cooker
Documents  >  Tutorial  >  declarationstatement
Declaration statement

Purpose of this chapter.

We will learn about the declaration statement.

Declaration of the variable.

A declaration statement will introduce a variable within a specific range of programs (scope). And, an instance of the specified class will be bound to the variable.

The variable can be accessed by using the variable name in the scope which it was declared.

A declaration statement is the following format.

class-name variable-name ;

This is a statement that ends with a semicolon after the two identifier. The first identifier is a class name. The second is a variable name.

Variables can be declared any number in any location. However, it is not possible to declare a variable with the same variable name in the same scope.

Variables with the same name can be declared if scope is different. In that case, the variable that is declared at the inside scope hides the variable that is declared at the outside scope.

Class name.

Class name represents the type of an instance that will be bound to the variable.

Variable name.

Variable name is an identifier that is used to access the variable.

The end of the declaration statement.

The end of the declaration statement is represented by a semicolon.

Copyright © Rice All rights reserved.