Home News DOC Class DL Others Cooker
Documents  >  Tutorial  >  Definition
Definition statement

The definition statement declares and initializes variables at the same time.


Table of contents:


Format

Class name

Variable name

Assignment symbol =

Expression

Semicolon

Example

Format

The format of the definition statement is:


Class-name Variable-name = Expression ;


The left side of the assignment symbol is a variable declaration.

It initializes the variable with the instance returned by the expression on the right side of the assignment symbol.

Class name

It represents a class that is bound to a variable.

Variable name

It is an identifier used to access a variable.

Assignment symbol =

It is a symbol for setting a value in a variable.

Expression

The expression creates an instance that is set in the variable. The class of the generated instance must be the same as the class name.

Semicolon

The end of a definition statement is represented by a semicolon.

Example

1:

class example

2:

int var1;// ♦1

3:

open method void someMethod()

4:

int var2 = 10; // ♦2

5:

if(true)

6:

int var3 = new int(100); // ♦3

7:

ei

8:

em

9:

ec

♦1: It is a field. Fields cannot be defined.

♦2: It has initialized with a literal.

♦3: It has initialized with a fitter.

Next
Previous
Copyright © Rice All rights reserved.