6.core Java Variables
6.core Java Variables
Class Members:
class Test
{
1.Variables;
2.Methods;
3.Constructors;
4.instance blocks;
5.static blocks;
}
1. Variables:
Types of Variables:
1. Instance Variables
2. Static Variables
3. Local Variables
4. Parameters
Variable Declaration:
<data type> <identifier>;
Examples:
int x;
float y;
String z;
Initialization:
<identifier> = <value / expression>;
Examples:
x = 10;
y = 1.2f;
z = "Welcome to Java";
x = x+30*5;
Example:
int x = 10;
double y = 1.23;
boolean b = true;
Static Area:
Instance Area:
[email protected] Cell: 78 42 66 47 66
Leela Soft Core Java (J2SE) Madhusudhan
Instance Variables:
Example:
class Test {
int x = 10; // instance variable
static int y = 20; // static variable
t.m1(100, 2.3);
}
}
Example:
class Test {
int x = 10; // instance variable
static int y = 20; // static variable
[email protected] Cell: 78 42 66 47 66
Leela Soft Core Java (J2SE) Madhusudhan
t.m1(100, 2.3);
}
}
Example:
class Test {
int x = 10; // instance variable
static int y = 20; // static variable
t.m1(100, 2.3);
}
}
[email protected] Cell: 78 42 66 47 66
Leela Soft Core Java (J2SE) Madhusudhan
t.m1();
}
}
Example:
class Test {
public static void main(String[] args) {
int y;
System.out.println("Local :" + y);
}
}
[email protected] Cell: 78 42 66 47 66
Leela Soft Core Java (J2SE) Madhusudhan
}
}
[email protected] Cell: 78 42 66 47 66