java variables examples
Example 1: Variables in java
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: Variables in java
public class LocalVariableExample
{
public void employeeDetails()
{
int empAge = 22;
String name = "Sachin";
}
public static void main(String[] args)
{
LocalVariableExample obj = new LocalVariableExample();
System.out.println("Employee name is : " + name + ", and age : " + empAge);
}
}