local variable java code example
Example 1: what is local variable in java
Local variables are declared in methods,
constructors, or blocks. Local variables
are created when the method, constructor
or block is entered and the variable will
be destroyed once it exits the method,
constructor, or block.
Example 2: instance variable java
A variable declared inside the class is called instance variable. Value of
instance variable are instance specific.
public class InstanceVariableDemo
{
int c;
public void subtract()
{
int x = 100;
int y = 50;
c = x - y;
System.out.println("Subtraction: " + c);
}
public void multiply()
{
int m = 10;
int n = 5;
c = m * n;
System.out.println("Multiplication: " + c);
}
public static void main(String[] args)
{
InstanceVariableDemo obj = new InstanceVariableDemo();
obj.subtract();
obj.multiply();
}
}
Example 3: java variable declared
java decleartion
int a, b, c;
int a = 10, b = 10;
byte B = 22;
double pi = 3.14159;
char a = 'a';