user15881
0
Q:

instance variable java

A variable declared inside the class is called instance variable. Value of 
instance variable are instance specific.
public class InstanceVariableDemo
{
   // instance variable declared inside the class and outside the method
   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();
   }
}
1
java decleartion 

int a, b, c;         // Declares three ints, a, b, and c.
int a = 10, b = 10;  // Example of initialization
byte B = 22;         // initializes a byte type variable B.
double pi = 3.14159; // declares and assigns a value of PI.
char a = 'a';        // the char variable a iis initialized with value 'a'
0
class Programmmer{
  
  String name;//instance variable
  int age;//instance variable
  
  
  public void drinkCoffee(){ 
    
  }
}
  
-1

New to Communities?

Join the community