instance variable java code example
Example 1: 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 2: java variable declared
java decleartion
int a, b, c;
int a = 10, b = 10;
byte B = 22;
double pi = 3.14159;
char a = 'a';
Example 3: 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 4: an instance variable java
Instance variable is property