Declaration statement is a statement to introduce variables into a program.
Table of contents:
The format is:
Class-name Variable-name ;
This is a statement ends with a semicolon after specifying the class name and variable name.
This statement introduces a variable into a particular scope and binds the specified class to the variable.
You can access to the variable by name within the declared scope.
Variables can be declared any number in any location. However, it is not possible to declare a variable with the same name in the same scope.
Variables with the same name can be declared if scope is different. In this case, the variable declared at the inside scope hides the outside variable with same name.
It represents a class that is bound to a variable.
This is an identifier used to access a variable.
The end of a declaration statement is represented by a semicolon.
open method void someMethod()
int x; // ♦1
int x; // ♦2
All are declarations for variables of the int class. These variables can only handle instances of the int class.
♦1 and ♦2 declare variables with the same name in different scope. Each hides the outer variable with the same name.