OneCompiler

Functions

1733

Types of Variables

  1. Local Variables
  2. Instance Variables
  3. Static Variables
Static Variables
Class Sum {
    int n1 = 10; // value of Instance  Variables are are instance specific.
    static int n2 = 20; //static variable is Common for all the instances of the class.
    void sum(){
        int n3 = 30; //local variable and they are Inside the body of a method.
        int total = n1+n2+n3;
    }
}