- Variables are the basic unit of storage in a java program.variables represents a memory location which holds data.
- A variable is defined as combination of an identifier, type and optional initializer.
- All variables have scope and which defines visibility and lifetime.
- All variables must be declared before they can be used.
- Syntax:- type identifier[=value][,identifier[=value]…];
- Type represents the data type of an identifier. The identifier is the name of the variable.
- You can initialize the variable by specifying an equal sign and value comma (,) is used to separate the variables
Variable declaration
for various types
Ex:- int a,b,c; // declares three integers a , b , c
Int a, b, c=4,
c=5; // declares a as integer value and
initialization of b ,c
Char x=’x’; //
variable x has the value ‘x’
Dynamic
initialization:-
Java allows variables to be initialized dynamically using
any expression valid at the time of the variable is declared.
Class Dyint
{
Public static void main (String args [])
{
Double a= 3.0, b= 4.0;
Double c = math.sqrt (a*a+b*b); // is initialized dynamically
System.out.println (“value of c is “+c);
}
}
0 comments :
Post a Comment
Note: only a member of this blog may post a comment.